Section 25.324. XMLHttpRequest.onreadystatechange: event handler function invoked when readyState changes


25.324. XMLHttpRequest.onreadystatechange: event handler function invoked when readyState changes

25.324.1. Synopsis

 Function onreadystatechange 

25.324.2. Description

This property specifies an event-handler function that is invoked each time the readyState property changes. It may also be invoked (but this is not required) multiple times while readyState is 3 to provide notification of download progress.

An onreadystatechange handler typically checks the readyState of the XMLHttpRequest object to see if it has reached 4. If so, it does something with the responseText or responseXML properties.

It is unspecified whether any arguments will be passed to the function. In particular, there is no standard way for the event-handler function to get a reference to the XMLHttpRequest object it is registered on. This means that it is not possible to write a generic handler function that can be used for multiple requests.

The XMLHttpRequest object is supposed to follow the DOM event model and implement an addEventListener( ) method for registering handlers for readystatechange events. (See Event.addEventListener( ), for example.) Since IE does not support the DOM event model, and since it is rare to require more than one event handler per request, it is safer to simply assign a single handler function to onreadystatechange.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net