我使用jQuery JavaScript库5.0上jQuery.getJSON()如何获得
我使用这个代码
var urlToGetToken = 'http://test.com';
$.getJSON(urlToGetToken, function (data) {
document.getElementById("demo3").innerHTML = data.access_token;
}).success(function() {
alert("second success");
})
.error(function() {
alert("error");
})
.complete(function() {
alert("complete");
});
请求的状态
我想打印在demo3中,状态码和错误消息以防Ajax请求失败。
我累了使用.error()...但没有成功。
任何想法?
如果你使用jQuery,你为什么用'document.getElementById'?只需使用'$(“#demo3”)。html(data.access_token);' – h2ooooooo
只是为了测试:-) – GibboK
你说你使用'.error()'但没有成功。你能给我们用这个'error()'调用的代码吗? – h2ooooooo