由于jQuery中的Ajax请求存在未定义的错误.但它在当地有效.在jquery1.3.2.js @ 3633行中引用错误
xhr.send(s.data);
Run Code Online (Sandbox Code Playgroud)
我的代码是:
$.ajax({
type: "POST",
url: 'index.php',
data: "action=showpath&type=images&path=&default=1",
cache: false,
dataType: "html",
success: function(data){
$('#addr').html(data);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
Run Code Online (Sandbox Code Playgroud)
代码中的警报显示我(0,'undefined');
我做错了什么?
cur*_*ter 23
如果您的ajax请求在完成之前被取消,则可能会发生这种情况.当用户通过刷新,单击链接或更改浏览器中的URL导航离开页面时,jQuery会抛出错误事件.您可以通过为ajax调用实现错误处理程序并检查xmlHttpRequest对象来检测这些类型的错误:
$.ajax({
/* ajax options omitted */
error: function (xmlHttpRequest, textStatus, errorThrown) {
if(xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)
return; // it's not really an error
else
// Do normal error handling
});
Run Code Online (Sandbox Code Playgroud)