jQuery ajax XML Http请求不起作用 [英] jQuery ajax XML Http Request not works

查看:102
本文介绍了jQuery ajax XML Http请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

There is an undefined error due to Ajax request in jQuery. But it works locally. Error referencing in jquery1.3.2.js @ 3633 line

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');

alerts in code shows me (0, 'undefined');

我在做什么错了?

推荐答案

如果您的Ajax请求在之前被取消,则可能会发生这种情况它完成了。当用户通过刷新,单击链接或更改浏览器中的URL离开页面时,jQuery引发错误事件。您可以通过为ajax调用实现错误处理程序并检查xmlHttpRequest对象来检测这些类型的错误:

This could be happening if your ajax request is getting canceled before it completes. jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. You can detect these types of errors by by implementing an error handler for the ajax call, and inspecting the xmlHttpRequest object:

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

这篇关于jQuery ajax XML Http请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆