文档指出error:option函数将可用:XHR实例,状态消息字符串(在这种情况下总是错误)和从XHR实例返回的可选异常对象(Book:JQuery in Action)
使用以下(在$ .ajax调用中)我能够确定我有一个"parsererror"和一个"超时"(因为我添加了timeout:option)错误
error: function(request, error){}
Run Code Online (Sandbox Code Playgroud)
您在错误选项中评估的其他内容是什么?你是否包含可选的异常对象?
编辑:其中一个答案表明所有返回错误...了解更多关于XHR实例中的值(用于调试)和异常对象将有所帮助
这是一个完整的$ .ajax调用:
$.ajax({
type: "post",
url: "http://myServer/cgi-bin/broker" ,
dataType: "text",
data: {
'_service' : 'myService',
'_program' : 'myProgram',
'start' : start,
'end' : end
},
beforeSend: function() {
$("#loading").removeClass("hide");
},
timeout: 5000,
error: function(request,error) {
$("#loading").addClass("hide");
if (error == "timeout") {
$("#error").append("The request timed out, please resubmit");
}
else {
$("#error").append("ERROR: " + error);
}
},
success: function(request) {
$("#loading").addClass("hide");
var t = eval( "(" + request + ")" ) ;
} // End success
}); // End ajax method
Run Code Online (Sandbox Code Playgroud)
感谢您的投入
Mat*_*att 43
我发现请求比错误更有用.
error:function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);
}
Run Code Online (Sandbox Code Playgroud)
xhr是XmlHttpRequest.
readyState值为1:loading,2:loaded,3:interactive,4:complete.
status是HTTP状态号,即404:未找到,500:服务器错误,200:ok.
responseText是服务器的响应 - 可以是来自Web服务的文本或JSON,也可以是来自Web服务器的HTML.
Zac*_*ach 22
查看jQuery源代码,除了成功之外,还有四种返回状态:
归档时间: |
|
查看次数: |
74957 次 |
最近记录: |