I was reviewing the request.js to see how the XHR request was done and I was puzzled to see the implementation.
Rather than use onreadystatechange I notice that you setTimeout to wait for 200 milliseconds and then check if readyState == 4. If its not 4 then you wait another 200 milliseconds.
Can you explain the reasoning behind this approach (or correct any misinterpretation I may have had).
Saturday, July 8, 2006
I don't have any strong evidence against using onreadystatechange but in my experience using polling is more simple and more reliable. Otherwise you still have to implement the timeout (in case of network error) and you have to clear the event handler when navigating away from the page (possibly even before receiving response) and you have different (synchronous) behavior when you develop from the filesystem etc. The downside is just small additional latency which I guess is acceptable in most cases.