检查ajax回调中的错误值
如何检查ajax回调错误中返回的错误值:
$.ajax({ url: "myurl", type: 'POST', dataType : "text", data : ({ json : myjson }), success : function(data) { }, error : function() { alert ('error'); } });
尝试访问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是http状态号。
alert("readyState: "+xhr.readyState); alert("status: "+xhr.status); alert("responseText: "+xhr.responseText);
类似这个问题
error : function(jqXHR, textStatus, errorThrown){ alert(jqXHR.status); }