0 out of 2 rated this helpful - Rate this topic

onreadystatechange event

[This documentation is preliminary and is subject to change.]

Sets or retrieves the event handler for asynchronous requests.

Syntax

HTML Attribute <element onreadystatechange = "handler(event)">
Event Property object.onreadystatechange = handler;
attachEvent Method object.attachEvent("onreadystatechange", handler)

Standards information

There are no standards that apply here.

Event information

SynchronousNo
BubblesNo
CancelableNo

Event handler parameters

This method has no parameters.

Remarks

The onreadystatechange event was introduced in Windows Internet Explorer 7.

To invoke this event, do one of the following:

  • Event handlers are called as needed after a request is sent.

Examples

The following script demonstrates how to set an asynchronous event handler that alerts the user when the readyState property of the request reaches complete (4). Note that you must set the event handler after calling open, which resets all properties of the XMLHttpRequest object to their initial value.


function reportStatus()
{
    if (oReq.readyState == 4 /* complete */) {
        if (oReq.status == 200 || oReq.status == 304) {
            alert('Transfer complete.');
        }
        else {
            // error occurred
        }
    }
}
var oReq = new XMLHttpRequest();
oReq.open("GET", "http://localhost/test.xml", true);
oReq.onreadystatechange = reportStatus;
oReq.send();

See also

XMLHttpRequest
XMLHttpRequest Constructor
readyState

 

 

Build date: 2/14/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ