December 13, 2002
readyState
Microsoft’s XMLHTTP object is an ActiveX component that lets you perform HTTP requests. The object has
four different states that it cycles through when performing a request. One of those states is called “interactive” and is decribed as such (from the MSDN documentation):
(3) INTERACTIVE Some data has been received. You can call responseBody and responseText to get the current partial results.
…meaning that at that point you should be able to examine the contents of the response so far. Let’s try this, shall we?
var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
xmlHTTP.onreadystatechange = handleStateChange;
function handleStateChange()
{
if (xmlHTTP.readyState == 3)
{
alert(xmlHTTP.responseText);
}
}
xmlHTTP.open("POST","/some/uri",true);
xmlHTTP.send();
Execution of this code produces an error in the handler:
The data necessary to complete this operation is not yet available.
…which troubles me greatly. Waiting until readyState is 4 (complete) works perfectly, but there’s an added complication: the URI /some/uri establishes a persistent connection, which means that unless the connection is terminated by the script or the server, readyState will always be 3 (interactive). According to the docs, I should be able grab the incomplete response from the server at this time, but apparently not. Possible reasons:
- the MSDN documentation is a big fat lie incorrect
- the XMLHTTP object has a huge buffer to fill before it will make the response available
- the object needs to see some sort of delimiter, like a null byte, as a signal to make the response text available
- I’m horribly misunderstanding the whole thing
UPDATE 3/4/2004: many. many people have written me to ask if I have found a workaround since I first posted this. I’m sorry to say that I have not.









Hello, do you have any progress about the ‘readyState’ issue? I am troubled by this problem too, would you please give me some advice if you have any new idea?
Thanks a lot!