Javascript 带jquery的跨域ajax POST ie7
这个脚本一直有问题,我设法让它在ie8上运行,在chrome fine上运行Javascript 带jquery的跨域ajax POST ie7,javascript,jquery,ajax,internet-explorer-7,xdomainrequest,Javascript,Jquery,Ajax,Internet Explorer 7,Xdomainrequest,这个脚本一直有问题,我设法让它在ie8上运行,在chrome fine上运行 initilize: function(){ $('#my_form').submit(function(){ if ($.browser.msie && window.XDomainRequest) { var data = $('#my_form').serialize(); xdr=new XDomainRequest(); function after_xhr_
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中使用该代码,因为旧浏览器不支持is跨域调用。您需要更改后端以执行JSONP调用,或者需要使用服务器端代理。您无法在IE7中使用该代码,因为旧浏览器不支持is跨域调用。您需要更改后端以执行JSONP调用,或者需要使用服务器端代理。也许您正在寻找JSONP,请参阅简单的答案:如果不更改为相同的域请求或使用JSONP而不是CORS,您无法在IE7中复制它。也许您正在寻找JSONP,简单的回答是,如果不更改为同一个域请求或使用JSONP而不是CORS,就无法在IE7中复制它。谢谢你的回答,我也这么认为。谢谢你的回答,我也这么认为。