这个脚本遇到了问题,我设法让它在 ie8 中工作,在 chrome 上工作得很好。
initilize: function(){
$('#my_form').submit(function(){
if ($.browser.msie && window.XDomainRequest) {
var data = $('#my_form').serialize();
xdr=new XDomainRequest();
function after_xhr_load()
{
response = $.parseJSON(xdr.responseText);
if(response.number =="incorrect format"){
$('#errors').html('error');
}
else
{
$('#errors').html('worked');
}
}
xdr.onload = after_xhr_load;
xdr.open("POST",$('#my_form').attr('action')+".json");
xdr.send(data);
} else {
$.ajax({
type: "POST",
url: $('#my_form').attr('action')+".json",
data: $('#my_form').serialize(),
dataType: "json",
complete: function(data) {
if(data.statusText =="OK"){
$('#errors').html('error');
}
if(data.statusText =="Created"){
response = $.parseJSON(data.responseText);
$('#errors').html('Here is your code:' +response.code);
}
}
});
}
return false;
});
}
我知道 ie7 没有 XDomainRequest() 对象。我怎样才能在 ie7 中复制这个。
提前谢谢
最佳答案
您不会让该代码在 IE7 中运行,因为该旧浏览器不支持跨域调用。您要么需要更改后端以执行 JSONP 调用,要么需要使用服务器端代理。
关于javascript - 跨域ajax POST ie7与jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12939038/