jQuery ajax XML Http请求不起作用

jQuery ajax XML Http请求不起作用,jquery,ajax,Jquery,Ajax,由于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", s

由于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,“未定义”)


我做错了什么?

无法立即告诉你,但这可能是index.php中服务器端的一些东西。最好的方法是使用http调试器查看原始响应。firefox扩展有一个非常好的扩展,是一个强大的选项。

如果您的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
});

我已经用firebug测试过了。显示错误响应,但其自身状态为200-OK。Ajax请求返回ajaxError,没有解释。我在上找到了相同的问题描述,但仍然没有解决方案。