【问题标题】:IE9 CORS XDomainRequest Access DeniedIE9 CORS XDomainRequest 访问被拒绝
【发布时间】:2016-08-13 12:32:45
【问题描述】:

在 IE9 中执行 XDomainRequest 时,我不断收到“拒绝访问”。
我已经尝试了很多不同的解决方案,目前没有任何效果。

注意:脚本在 HTTP 上,而它正在请求的服务器是 HTTPS

下面是我的代码:

        let xhr = new XMLHttpRequest();

        if ('withCredentials' in xhr){
            xhr.open('POST', XHR_URL, true);
        } else if (typeof XDomainRequest != 'undefined'){
            xhr = new XDomainRequest();
            xhr.open('POST', XHR_URL);
        } else {
            xhr = null;
            return;
        }

        xhr.setRequestHeader('Content-type', 'text/plain');

        xhr.onreadystatechange = () => {
            if(xhr.readyState == 4 && xhr.status == 200) {
                // do something
            }
        }

        xhr.onprogress = function () { };
        xhr.ontimeout = function () { };

        setTimeout(function () {
            xhr.send(params);
        }, 0);

需要帮助,谢谢!

【问题讨论】:

    标签: ajax xmlhttprequest internet-explorer-9 xdomainrequest


    【解决方案1】:

    如果您从 IE9 开始,那么您的 xhr 会调用 new XDomainRequest(a.k.a xdr)。但是,xdr 没有“setRequestHeader”。

    【讨论】:

      猜你喜欢
      • 2014-01-04
      • 2012-01-17
      • 2014-11-20
      • 2012-05-01
      • 2015-07-01
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      相关资源
      最近更新 更多