I have already asked on the jQuery discussion group about this but as far as I can discern the problem lies in Internet Explorer's XHR implementation and needs to be addressed at that level.

I am working on an AJAX application, and thought it would be a good idea to give the user some indication of data transfer progress as most AJAX apps don't do this and I personally find being made to wait for a download without being kept informed of it's progress frustrating.

I did some reading up and discovered that when the XHR object is in readyState 3 (interactive) then the partial data that has been transferred thus far is available in responseText. I figured that if I can get the server to send an accurate Content-length header and then measure the length of the responseText string at regular intervals I could generate a download progress report. Here's the code I wrote to do this:

PHP Code:
var myTrigger;
progressElem = $('#progressCounter');
ajax ({
type            'GET',
dataType        'xml',
url             'somexmlscript.php' ,
beforeSend      : function (thisXHR)
myTrigger setInterval (function ()
                        if (
thisXHR.readyState 2)
totalBytes  thisXHR.getResponseHeader ('Content-length');
dlBytes             thisXHR.responseText.length;
totalBytes 0)?
progressElem.html (Math.round ((dlBytes totalBytes) * 100) +
progressElem.html (Math.round (dlBytes 1024) + "K");
complete        : function ()
clearInterval (myTrigger);
// Other cleanup code goes here
success         : function (response)
// Process XML

I found that this worked great in FireFox 1.5/Win, Opera 9/Win and Safari 3/Win, but I would get an exception in Internet Explorer. Research into this problem turned up this link: http://jszen.blogspot.com/2005/03/xm...eadystate.html

According to the page linked to above, you cannot access responseText while in readyState 3, even though the MSDN documentation says that you can.

Am I doing something wrong? Does accessing responseText in readyState 3 require a different syntax in IE? Or is there some other attribute of the XHR object I can access in IE that I can use to generate the download progress report? While the report feature strictly speaking isn't necessary I think it would be a big help to improving the useability of AJAX apps that have to download a big chunk of data.