【问题标题】:Cross-domain ajax in IE 8,9 [duplicate]IE 8,9 中的跨域 ajax [重复]
【发布时间】:2013-07-09 14:22:54
【问题描述】:

我有一个 ajax 请求

$.ajax({
   type: "GET",
   url: url,
   success: function(xml) {
        $('.post-msg').append(processXml(xml, config));
   },
   error: function(jqXhr, textStatus, errorThrown) {
       var errorMsg = "Request on url: " + url + " failed: " + textStatus + " error:" + errorThrown;
            alert(errorMsg);
        }
    });

问题是它在 IE 8,9 中不起作用,老板建议使用 post message。在 IE 8,9 中使这个请求工作的方法是什么?

【问题讨论】:

    标签: javascript ajax jquery cross-domain


    【解决方案1】:

    如何在IE8/9中对支持CORS的网站进行跨域请求,讲了here,主要是使用IE-unique对象XDomainRequest而不是XMLHttpRequest

    您可以在msdn XDomainRequest page 上查看代码示例

    // 1. Create XDR object 
    var xdr = new XDomainRequest(); 
    // 2. Open connection with server using GET method
    xdr.open("get", "http://www.contoso.com/xdr.aspx");
    // 3. Send string data to server
    xdr.send(); 
    

    【讨论】:

      猜你喜欢
      • 2013-07-07
      • 2013-12-07
      • 2012-06-05
      • 2014-04-01
      • 1970-01-01
      • 2013-02-03
      • 2012-09-17
      • 2011-03-22
      • 2012-02-20
      相关资源
      最近更新 更多