IE9 RTM - XDomainRequest issued requests may abort if all event handlers not specified RRS feed

  • General discussion

  • I just struggled with a problem in a web application that I develop, and wanted to inform the rest of the community and the IE developers in case they run into it (or would like to fix it in an IE service pack).

    I'm using XDomainRequest to issue requests. Most of my requests were succeeding as expected (and all were in IE9 Beta and IE8), but occasionally some specific requests would abort in the browser after the response was received. The server would return the full response and a 200 HTTP response code, but inspecting the requests in Fiddler shows that they're inexplicably aborted occasionally (one specific response of approximately 917 bytes of JSON which results in a bit of browser UI updating would abort approximately 70% of the time... another request which is just a no-op would succeed nearly 100% of the time).

    The solution in my case was to add the following event handler to the XDomainRequest object:
    invocation.onprogress = function() {};

    Other handlers may also be necessary (the complete list that I now have specified are: ontimeout, onerror, onload, onprogress) to avoid this.

    I hope this saves someone else some time!

    Wednesday, March 23, 2011 8:57 PM

All replies

  • With the nature of how onprogress works, I'm guessing that the requests that succeeded simply never attempted to call the onprogress handler (I hadn't tested that). Prior versions of IE must have gracefully handled the onprogress event handler being unspecified (which is proper), whereas IE9 aborts.

    I mentioned the other handlers because I've heard reports of ontimeout causing some similar problems if unspecified, but didn't test removing it in my code personally. It's possible that only the onprogress handler is required.

    Wednesday, March 23, 2011 9:13 PM
  • Justin - thanks for this; this exactly fixed an issue I was having with the same symptoms.
    Sunday, May 22, 2011 8:15 PM
  • So glad I found this. Many of my calls in IE seemed to be just disappearing - none of the event handlers were ever called: onload, onerror, ontimeout - adding the empty onprogress seems to have fixed it.
    Thursday, September 22, 2011 3:14 PM
  • Oh. My. God. Thank you SO much for this post. I've been racking my brain over this for the past 2 hours. I would have never figured it out...
    Saturday, November 12, 2011 2:59 AM
  • Thanks heaps for this post. Thought I was going crazy with a request the worked fine for ages and then suddenly started aborting.
    Friday, January 20, 2012 3:50 AM
  • Thank  you. Thank you. Thank you... 

    God bless you man!!! You saved my life... I was going to commit suicide :P 

    Friday, April 6, 2012 12:52 AM
  • This solution was not the full solution for me.

    This is the remainder of the solution - that worked successfully for me.  Only adding the handler did not change/fix the issue, but is required.  Here is the full solution incorporating suggestions from other comments on the blog post:

     var xdr = new XDomainRequest();
    // Suggested this may be required under some circumstances.'POST', statUrl);
    // Must attach
    xdr.onload = function () { };
    xdr.onerror = function () { };
    xdr.ontimeout = function () { };
    xdr.onprogress = function () { };
    xdr.timeout = 0;
    // Suggested that some initialization time may be required to prep the XDomainRequest prior to send being called.
    var sendSetTimeout = 200;
    // Do not unwrap .send method.  Required to run on a separate thread.
    setTimeout(function () {
    }, sendSetTimeout);

    Sunday, February 17, 2013 5:11 AM
  • Thank you, kind sir! This saved me a lot of trouble indeed!!
    Tuesday, May 5, 2015 6:24 PM
  • Thank you man! I spend two days before found your question! Wondering why it is not mentioned in MSDN about XDomainRequest request
    Wednesday, July 1, 2015 3:00 PM