ajaxerror
$(document).ajaxError(function(event, request, ajaxOptions, thrownError){
if ( 4==request.readyState) {
alert(ajaxOptions['url'] + " did not return valid json data");
}
else {
alert("something else wnet wrong");
}
});
$.ajax() $.getJSON()
function foo() {
$.ajax({
type: "GET",
url: "http://localhost/test.txt",
success: function (data, textStatus) {
alert("succuess");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("request failed: " + textStatus);
},
dataType: "json"
});
}
edit: , ajax (dataType: "json" ) getJSON() ( .ajax(dataType: "json" ), data = window["eval"]("(" + data + ")")... , , t () script. , firebug , html- json-.
dataType: "string" jsson parser lib.