【发布时间】:2014-08-20 13:27:05
【问题描述】:
我正在尝试将表单从我的网站发布到服务器(不是同一个域)。 在 Chrome、Firefox 和 IE10+ 上一切正常,但我必须让它也能在 IE9 上运行。
这是我的代码
$("#sendform").click(function() {
// Content
var infosForm = {};
infosForm.firstname = $('input[name=firstname]')[0].value;
infosForm.name = $('input[name=name]')[0].value;
infosForm.phone = $('input[name=tel]')[0].value;
infosForm.mail = $('input[name=mail]')[0].value;
infosForm.commentaire = $('textarea[name=comment]')[0].value;
var isChecked = $('.messageCheckbox:checked').val();
if (isChecked == "on")
{
infosForm.isNewsletter = "on";
}
else
{
infosForm.isNewsletter = "off";
}
$.ajax({
url:'http://my.website.com/form.ashx',
type:'post',
data:infosForm,
cache:false, //normaly this is quite useless since it's a post, but It's known to help with IE... still not.
crossDomain:true,
//showing feedback
success:function(){
$("#contact form").hide();
$("#contact form").fadeIn('slow').html("<p>Success</p>");
//trackEvent();
},
error:function(){
$("#contact form").hide();
$("#contact form").fadeIn('slow').html("<p>Error</p>");
}
});
});
根据 fiddler 的说法,IE9 似乎没有发送任何请求并直接显示错误消息。
注意:这里使用 jQuery 1.8.3。
【问题讨论】:
-
你需要做一点调试。对我来说,没有什么明显的错误,尤其是对于 IE9。查看 IE 的开发人员工具,看看您是否看到任何特定错误(如网络错误或语法错误)。
-
我在来sof之前尝试过调试,但是IE根本没有发送错误信息。
-
看这里(评论3):bugs.jquery.com/ticket/12097
-
嗨,我尝试了这里提到的技巧,但没有成功,我想因为我使用的是更新的 jQuery 版本(1.8.3),这个错误已得到纠正,我们必须寻找其他东西。
标签: javascript jquery ajax internet-explorer internet-explorer-9