A
A
Alexander Yelagin2016-10-28 15:34:39
JavaScript
Alexander Yelagin, 2016-10-28 15:34:39

How to send a cross domain request in IE8?

Hello!
It is necessary to send a cross-domain request from different browsers. It works in Firefox and Chrome, it works in IE11, but it doesn't work in IE8.
Code example:

if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest();
        }
        else if(window.ActiveXObject){
            try{
                xhr = new ActiveXObject('Msxl2.XMLHTTP');
            } catch (e){}
            try{
                xhr = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    if(xhr){
        xhr.open("POST", 'http://mysite.ru', true);//отказано в доступе
        xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
        xhr.onreadystatechange = function() {};
        xhr.withCredentials = true;
        xhr.send(json);
   }

And in this line in IE8 an error pops up - xhr.open("POST", ' mysite.ru ', true); error - access denied.
Perhaps this is due to the features of the version, I don’t know, I googled and could not find an answer.
In the end, I send a cross-domain request from site A to site B, in browsers - Chrome, Firefox and IE11 it works fine. Some older versions of IE have a bug. How to overcome this problem? I don’t offer the option to send using Jquery, I use pure JS and for the sake of sending requests, using either is not an option.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antonre, 2016-10-29
@antonre

First, check if the web server of the destination site is returning the header .
More details can be found here .
Secondly, if the request is not on https, then IE8 will issue a warning window.
If you select "No" in it, then the choice is remembered for the duration of the session, and there will be an access error.
IE9 uses XDomainRequest, which is a stripped-down XMLHttpRequest.
It is subject to restrictions:
Подробнее можно почитать здесь

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question