IE AJAX跨浏览器问题

发布于 2024-12-09 10:17:28 字数 1410 浏览 1 评论 0原文

我有以下 AJAX 功能:

function ajaxDesignerBrandInfo()
{
    var D = wrapFormValues('#designer-brand-form');
    var recursiveEncoded = $.param(D);  
    /*
    $.post("/api/designer_brand/", { data : recursiveEncoded }, function(data) 
    {
        var results = $.parseJSON(data);
        window.location = "/register/designer-product/"; 
    });*/

    $.ajax( { type: "POST", 
              url: "/api/designer_brand/", 
              data : { data : recursiveEncoded },
              success: function(data) { 
                console.log(data);
                setTimeout(function() {
                window.location = "/register/designer-product/";
            },0);
              },
              error: function (xhr, ajaxOptions, thrownError ){
                                alert(xhr.status);
                                alert(thrownError); }
        });

    return false;   

}

以及相应的表单

<form id="designer-brand-form" name="form" method="post" action="" onSubmit="ajaxDesignerBrandInfo(); return false;"> 
....
</form>

提交在 Chrome、Safari 和 FireFox 上运行良好,将我正确地移至

/register/designer-product/

,但在 IE9 中,提交似乎

  1. 永远不会到达服务器

  2. 清除表单并重定向回我所在的当前页面(其中存在此​​表单)。

我可以通过 FireFox 确认没有 javascript 错误导致此失败。有时它确实有效,但我似乎不能总是以同样的方式重现此错误

有人请解释一下这是怎么回事?

谢谢

I have the following AJAX function:

function ajaxDesignerBrandInfo()
{
    var D = wrapFormValues('#designer-brand-form');
    var recursiveEncoded = $.param(D);  
    /*
    $.post("/api/designer_brand/", { data : recursiveEncoded }, function(data) 
    {
        var results = $.parseJSON(data);
        window.location = "/register/designer-product/"; 
    });*/

    $.ajax( { type: "POST", 
              url: "/api/designer_brand/", 
              data : { data : recursiveEncoded },
              success: function(data) { 
                console.log(data);
                setTimeout(function() {
                window.location = "/register/designer-product/";
            },0);
              },
              error: function (xhr, ajaxOptions, thrownError ){
                                alert(xhr.status);
                                alert(thrownError); }
        });

    return false;   

}

And the corresponding form

<form id="designer-brand-form" name="form" method="post" action="" onSubmit="ajaxDesignerBrandInfo(); return false;"> 
....
</form>

The submission works great on Chrome, Safari and FireFox, moving me to

/register/designer-product/

Correctly, but in IE9, the submissions seems to

  1. Never make it to the server

  2. clear the form and redirect back to the current page i am on (in which this form exists).

I can confirm via FireFox there are no javascript errors causing this to fail. And sometimes it actually works, but I cannot seem to always reproduce this error in the same way

Someone Please explain WTF is going on?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟柳画桥 2024-12-16 10:17:28

我相信你的问题是 IE 默默地抛出 Javascript 错误。 Firefox 不会抛出 JS 错误并不意味着 IE 也不会。检查 IE 中的 JS 错误(请参阅此链接这个一个)。找到错误,你就会找到解决方案。

另外,尝试 Fiddler,它是一个独立的 Windows 工具,充当代理服务器,并会告诉您正是您的 AJAX 流量的样子。

您的具体问题可能是 console.log 调用。这是 Firebug 的东西(Chrome 支持)。我认为 IE 不会,除非您采取措施添加它。请参阅:IE8 中的 console.log 发生了什么?

I believe your issue is that IE is silently throwing a Javascript error. Just because Firefox doesn't throw a JS error one doesn't mean that IE doesn't. Check for JS errors in IE (see this link or this one). Find the error and you'll find the solution.

Also, try Fiddler, which is a standalone Windows tool that acts as a proxy server and will tell you EXACTLY what your AJAX traffic looks like.

Your specific problem may be the console.log call. That is a Firebug thing (that Chrome supports). IE does not, I think, unless you take steps to add it. See: What happened to console.log in IE8?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文