【问题标题】:Cross domain ajax POST ie7 with jquery使用 jquery 跨域 ajax POST ie7
【发布时间】:2012-10-17 16:33:51
【问题描述】:

这个脚本有问题,我设法让它在 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 中复制它。

谢谢,提前

【问题讨论】:

标签: javascript jquery ajax internet-explorer-7 xdomainrequest


【解决方案1】:

您不会让该代码在 IE7 中工作,因为旧浏览器不支持跨域调用。您要么需要更改后端以执行 JSONP 调用,要么需要使用服务器端代理。

【讨论】:

  • 感谢您的回答,我想了很多。
猜你喜欢
  • 2015-02-03
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
  • 2012-05-18
  • 2011-03-31
  • 2013-06-04
相关资源
最近更新 更多