I’ve written previously on how to handle AJAX requests for Internet Explorer but recently we came across a strange issue where the requests were being aborted by IE before the response was finished being delivered. Using Fiddler and Firebug, we were able to see that the request was being made properly, and even the response was coming back properly, but at some point, IE would simply stop accepting the data if it was not a very short response.
The problem was even more perplexing because it did not happen every time and it did not happen the same in all versions of IE, in fact IE 9 had more difficulty than IE 7.
You might be familiar with the typical way of making an AJAX request using XDR for Internet Explorer. It would generally look like the following:
//USING JQUERY
if ($.browser.msie && window.XDomainRequest) {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", "someurl");
xdr.onload = function () {
var JSON = $.parseJSON(xdr.responseText);
if (JSON == null || typeof (JSON) == 'undefined')
{
JSON = $.parseJSON(data.firstChild.textContent);
}
processData(JSON);
};
xdr.send();
}
The process goes like this:
- Create the XDomainRequest object
- Define the request type (GET,POST) and the request path (URL) in .open()
- Define an event handler to capture the response in .onload()
- Send the request using .send()
Depending on what you are returning, this is usually all you need.If you run into the problem that we were having, you need to do a little more to fix it.
The Solution
The problem has to do with IE timing out the request even though data is being transmitted. By defining some additional event handlers and specifying a timeout value of 0, IE will not abort the request prematurely. Your mileage may vary but for us the solution was to define the following handlers as empty:
xdr.onprogress = function () { };
xdr.ontimeout = function () { };
xdr.onerror = function () { };
Then wrap the send() function in a timeout declaration:
setTimeout(function () {
xdr.send();
}, 0);
Producing the final resulting XDR call of:
if ($.browser.msie && window.XDomainRequest) {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", "someurl");
xdr.onload = function () {
var JSON = $.parseJSON(xdr.responseText);
if (JSON == null || typeof (JSON) == 'undefined')
{
JSON = $.parseJSON(data.firstChild.textContent);
}
processData(JSON);
};
xdr.onprogress = function(){ };
xdr.ontimeout = function(){ };
xdr.onerror = function () { };
setTimeout(function(){
xdr.send();
}, 0);
}
Matthew Mombrea
Latest posts by Matthew Mombrea (see all)
- Hacked? Here’s How To Remove The Dreaded Google Malware Warning - March 21, 2013
- How to sort alphanumeric values with jQuery and C# - October 25, 2012
- Global AJAX error handling with jQuery - September 7, 2012
- How to create multiple 301 redirect urls in ASP.NET MVC - March 29, 2012
- Internet Explorer Aborting AJAX Requests : FIXED - March 19, 2012

This doesn’t work for a POST json operation. If I’m looking to use json data to get a request in a subdomain. Currently M$’s craptacular browsers inhibit such transfer as x-domain. The XDR seems like the only alternative to jsonp, but I’m not seeing it working.
Andrew,
Check these posts to see if the help your issue:
http://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/
http://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-xml-response-for-iefirefoxchrome-safari-jquery/
Thanks. This helped greatly on a get json XDR that was mysteriously barfing in IE9.
It’s pathetic that IE requires one to jump through such odd hoops.
Bravo. This saved me a lot of pain and anguish.
I an not a computer buff could you ive a step by step procedure
on how to fix this “aborting” problem I have Vista basics.
Thanks this helps me
Thanks, just what I needed!
I had given up on a solution until I found this. Now our IE9 users can use SVG, and not Flash! Awesome!
Just to save anyone else that has to do this with IE some grief. You have to set the ontimeout, onprogress, onload, onerror, and timeout values AFTER the xdr.open method. Also, on this line:
setTimeout(function () {
xdr.send();
}, 0);
I had to change it to:
setTimeout(function () {
xdr.send();
}, 500);
To get it to work. My theory is that initializing this XDomainRequest object takes some time depending on the resources of the client box. 500ms was a good value for us to get a variety of host machines to work consistently.
Thank you so much for this!
You are a god among men. I spent hours trying to figure out this goofy intermittent IE9 problem.
Thanks a lot for this help !