XDomainRequest aborts POST on IE 9

I am making an Ajax call with a cross zone.

My code is:

if (window.XDomainRequest) // Check whether the browser supports XDR.
{
    xdr = new XDomainRequest(); // Create a new XDR object.
    if (xdr) {
        xdr.timeout = 3000;//Set the timeout time to  3 second.
        xdr.onload = function () {
            alert("Success");
        };
        xdr.onerror = function () {
            alert("Error");
        };
        xdr.ontimeout = function () {
            alert("Error");
        };
        xdr.open("post", urlSearch);
        xdr.send();
    }
}
else {
    $.ajax({
        url: urlSearch,
        type: 'POST',
        dataType: 'json',
        timeout: 3000,
        success: function (data) {
            alert("Success");
        },
        error: function () {
            alert("Error");
        }
    });
}

The above code works fine in all browsers, but in IE sometimes an error like (interrupted) appears.

To overcome this error, I searched on Google and did not find a suitable solution.

You can see the error message in which it is displayed (interrupted). http://postimg.org/image/k01u6t9v5/

When I make an individual call to a specific URL, it does not show any (interrupted) messages (showing a alert about the readiness). But when I make some calls (for example, in the image), it shows this type of error.

How to overcome this problem?

Please, help

Thanks in advance

+5
source share
1

, , : onerror; ; ontimeout; onload. , :

. , . , xdr.send setTimeout.

, , , . , . setTimeout .

: 'this'. , . GET, POST. YMMV.

:

if (window.XDomainRequest) // Check whether the browser supports XDR.
{
    xdr = new XDomainRequest(); // Create a new XDR object.
    if (xdr) {
        xdr.timeout = 3000;//Set the timeout time to  3 second.
        xdr.onload = function () {
            alert("Success");
        };
        xdr.onerror = function () {
            alert("Error");
        };
        xdr.ontimeout = function () {
            alert("Error");
        };
        // this also needs to be set
        xdr.onprogress = function() {
            window.console.log('progress');
        };
        xdr.open("post", urlSearch);
        xdr.send();
    }
}
else {
    $.ajax({
        url: urlSearch,
        type: 'POST',
        dataType: 'json',
        timeout: 3000,
        success: function (data) {
            alert("Success");
        },
        error: function () {
            alert("Error");
        }
    });
}
+9

All Articles