检查ajax回调中有什么错误值 [英] Check what error value is in ajax callback
本文介绍了检查ajax回调中有什么错误值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查ajax回调错误中返回的错误值:
How can I check what the error value returned is in ajax callback error :
$.ajax({
url: "myurl",
type: 'POST',
dataType : "text",
data : ({
json : myjson
}),
success : function(data) {
},
error : function() {
alert ('error');
}
});
推荐答案
尝试为ajax调用的错误部分访问以下参数:
Try accessing these parameters for your error part of the ajax call:
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调用的一部分,您可以用逗号分隔它们.举个小例子:
They are part of the ajax call you seperate them with a comma. So a little example:
$.ajax({
success: function(data) {
},
error: function(xhr) {
}
});
更新: 基本上xhr.status是http状态编号.
Update: Basically xhr.status is the http status number.
alert("readyState: "+xhr.readyState);
alert("status: "+xhr.status);
alert("responseText: "+xhr.responseText);
这篇关于检查ajax回调中有什么错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文