IE9 CORS XDomainRequest Access Denied

319 views Asked by At

I'm keep getting 'Access Denied' when doing XDomainRequest in IE9.
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

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!

1

There are 1 answers

0
pebC On

If you start on IE9, then your xhr calls new XDomainRequest(a.k.a xdr). But, xdr doesn't have 'setRequestHeader'.