如何检查ajax回调错误中返回的错误值:
$.ajax({
url: "myurl",
type: 'POST',
dataType : "text",
data : ({
json : myjson
}),
success : function(data) {
},
error : function() {
alert ('error');
}
}); 发布于 2012-06-19 06:41:37
尝试为ajax调用的错误部分访问以下参数:
error: function (request, status, error) {
alert(request.responseText);另一个例子:
error: function(xhr) {
if(xhr.status == 422) {
alert(parseErrors(xhr));
} else {
alert('An error occurred while processing the request.');
}它们是ajax调用的一部分,您可以用逗号分隔它们。下面是一个小例子:
$.ajax({
success: function(data) {
},
error: function(xhr) {
}
});更新:基本上就是xhr.status的状态号。
alert("readyState: "+xhr.readyState);
alert("status: "+xhr.status);
alert("responseText: "+xhr.responseText);发布于 2012-06-19 06:32:47
与此question类似
error : function(jqXHR, textStatus, errorThrown){
alert(jqXHR.status);
}http://api.jquery.com/jQuery.ajax/
https://stackoverflow.com/questions/11092007
复制相似问题