但是,您可以在成功函数中添加状态和xhr变量。状态变量包含以下字符串之一:"success", "notmodified", "error", "timeout",或"parsererror", xhr变量包含返回的XMLHttpRequest对象
(可以在w3schools找到) < / p >
$.getJSON(url, datatosend, function(data, status, xhr){
if (status == "success"){
//do something with the data
}else if (status == "timeout"){
alert("Something is wrong with the connection");
}else if (status == "error" || status == "parsererror" ){
alert("An error occured");
}else{
alert("datatosend did not change");
}
});