我正在尝试通过使用JQuery的ajax调用获取JSON字符串,但是succes方法没有触发。当我通过完整方法检查状态时,它确实显示代码200和成功。
function init() {
$.ajax( {
type: "GET",
dataType: "json",
url:"posts.json",
succes: loadedSucces,
error: loadedError,
complete: loadedComplete
});
}
function loadedSucces(data,textStatus,jqXHR) {
var jsonObject = data;
$.each(jsonObject, function(key, val) {
console.log("\n" + key + " ====> " +val + "\n");
});
}
function loadedComplete(data, textStatus, jqXHR) {
console.log(textStatus);
console.log(data);
}
function loadedError(jqXHR,textStatus,errorThrown) {
console.log(jsonStatus+": "+errorThrown);
}
完成控制台输出:
success
postHandler.js:29 Object {readyState: 4, responseText: "[{"id":0,"title":" What is Lorem Ipsum ?","content… or non-characteristic words etc.\n","tags":[]}]↵", responseJSON: Array[4], status: 200, statusText: "OK"}
答案 0 :(得分:2)
成功与2 s的结合
function init() {
$.ajax( {
type: "GET",
dataType: "json",
url:"posts.json",
success: loadedSucces,
error: loadedError,
complete: loadedComplete
});
}