2009-06-21 57 views
10

由于jQuery中的Ajax请求存在未定义的错误。但它在本地工作。错误jquery1.3.2.js引用@ 3633线jQuery XMLHttpRequest错误

xhr.send(s.data); 

我的代码是:

$.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); 
    }  
}); 

警报代码显示我的(0, '未定义');

什么,我做错了什么?

回答

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 
}); 
0

无法分辨ya,但它可能是在index.php服务器端的东西。最好的方法是使用http调试器查看原始响应。 Firebug firefox扩展有一个不错的选择,fidder2是一个很好的选择。

+0

我已经用萤火虫测试了它。有错误的响应显示,但它自己的状态是200 - 确定。 Ajax请求返回ajaxError,没有解释。 – 2009-06-21 23:46:29