【发布时间】:2018-08-29 15:34:00
【问题描述】:
当我尝试获取外部 json 对象时,我每次都会收到“Uncaught SyntaxError: Unexpected token :”。我已经尝试使用 json 和 jsonp 来获取这些值,但从来没有工作过。
这里是链接:http://177.54.57.242:8080/ws_VerifSenhaPac_RetJSON?aPaciente=181927&aSenha=MVCARS1
jQuery(document).ready(function(){
//evento quando clicar no link com id="pegar-valor"
jQuery("#pegar-valor").click(function(){
//pegamos o valor do input
var usuario = jQuery("input[name=usuariologin]").val();
var senha = jQuery("input[name=usuariosenha]").val();
//mostramos o valor com alert()
//jQuery(this).attr('href', 'http://177.54.57.242:8080/ws_VerifSenhaPac_RetJSON?aPaciente=' + usuario + '&aSenha=' + senha + '');
//var url = 'http://177.54.57.242:8080/ws_VerifSenhaPac_RetJSON?aPaciente=' + usuario + '&aSenha=' + senha + '?callback=?';
var url = "http://177.54.57.242:8080/ws_VerifSenhaPac_RetJSON?aPaciente=181927&aSenha=MVCARS1&callback=?";
jQuery.getJSON( url, function ( result ) {
var objeto = JSON.parse( result );
console.log(objeto.StatusSenha);
});
jQuery.ajax({
url: 'http://177.54.57.242:8080/ws_VerifSenhaPac_RetJSON?aPaciente=181927&aSenha=MVCARS&?callback=?',
dataType: 'JSONP',
type: 'GET',
success: function (data) {
console.log('teste');
}
});
});
});
【问题讨论】:
标签: javascript jquery json jsonp