jQuery XMLHttpRequest错误
由于jQuery中的Ajax请求存在未定义的错误。 但它在当地有效。 在jquery1.3.2.js @ 3633行中引用错误
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,’undefined’);
我做错了什么?
如果您的ajax请求在完成之前被取消,则可能会发生这种情况。 当用户通过刷新,单击链接或更改浏览器中的URL导航离开页面时,jQuery会引发错误事件。 您可以通过为ajax调用实现error handling程序并检查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 });
无法告诉ya,但它可能是index.php中服务器端的东西。 最好的方法是使用http调试器查看原始响应。 Firebug firefox扩展程序非常好, fidder2是一个很好的选择。