简体   繁体   English

IE9 CORS XDomainRequest 访问被拒绝

[英]IE9 CORS XDomainRequest Access Denied

I'm keep getting 'Access Denied' when doing XDomainRequest in IE9.在 IE9 中执行 XDomainRequest 时,我不断收到“拒绝访问”的消息。
I Have tried lots of different solutions, nothing works so far.我尝试了很多不同的解决方案,到目前为止没有任何效果。

Note: the script is on HTTP while the server it's doing request to is HTTPS注意:脚本在 HTTP 上,而它正在请求的服务器是 HTTPS

Below is my code:下面是我的代码:

        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);

Need help, Thanks!需要帮助,谢谢!

If you start on IE9, then your xhr calls new XDomainRequest (aka xdr).如果您从 IE9 开始,那么您的xhr将调用新的XDomainRequest (又名 xdr)。 But, xdr doesn't have ' setRequestHeader '.但是, xdr没有“ setRequestHeader ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM