Search code examples
javascriptasp.netajaxauthenticationxmlhttprequest

Why is my XMLHttpRequest being aborted?


I have an XMLHttpRequest that I'm sending to log in to a remote server. I'm taking the login parameters (username and password) and sending them as json. Here's my code:

var json_data = JSON.stringify({
    "method": "login",
    "user_login": user,
    "password": password
});

var post_url = "server_url";


var crossRequest = new XMLHttpRequest();
crossRequest.open('POST', post_url, true);    //Async
crossRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
crossRequest.withCredentials = true;

crossRequest.onreadystatechange = function () {
    if (crossRequest.readyState == 4) {

        alert("Logged in!");
    }
}


crossRequest.onabort = function () {
    alert("ERROR: Aborted.");
}

crossRequest.onerror = function () {
    //alert("Error occurred, status: " + crossRequest.status);
}

crossRequest.onload = function () {
    if (crossRequest.status == 200)
    {
        alert("Logged in!");
    }
    else 
    {
        alert("An error occurred, status: " + crossRequest.status);
    }
}

crossRequest.send(json_data);

It works just fine in Chrome, but in IE 11 it always aborts, seemingly before sending anything:

IE 11 Dev Panel Network

IE 11 Dev Panel Error

What could be causing this, and how can I fix it?


Solution

  • Seems like existing IE11 issue

    https://connect.microsoft.com/IE/feedback/details/877525/ie11-returns-status-0-during-ajax-post-operation-from-an-iframe-xmlhttprequest-network-error-0x2ee4#tabs

    IE10/IE11 Abort Post Ajax Request After Clearing Cache with error "Network Error 0x2ef3"

    https://connect.microsoft.com/IE/feedback/details/852785/ie10-network-error-0x2ee4-https-proxy-ajax