IE AJAX跨浏览器问题
我有以下 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 中,提交似乎
永远不会到达服务器
清除表单并重定向回我所在的当前页面(其中存在此表单)。
我可以通过 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
Never make it to the server
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信你的问题是 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?