If you send two asynchronous requests in quick succession I presume this involves two different instances of the XMLHttpRequest.

Are you supposed to allocate a different onsteadystatechange function to each different instance of XMLHttpRequest (which seems a bit awkward). I have tried to use a single "pipe-like" function and then try and identify the instance that caused the event by inspecting event properties such as window.event.srcElement. This yields null.

Maybe one could keep an array of request object instances and test then one at a time for correct readystate to find which request has returned.

Any "right" way of doing this. Many thanks.

7 Years
Discussion Span
Last Post by Airshow


You can write a single function and attach it as the handler for onsteadystatechange to different instances of XMLHttpRequest.

Inside the handler, refer back to the instance of XMLHttpRequest that fired it with this . See http://www.w3.org/TR/XMLHttpRequest/

Of course, if you need to do very different things onsteadystatechange in each instance of XMLHttpRequest, then attach different functions.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.