2 out of 10 rated this helpful - Rate this topic

onreadystatechange event

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)

Event information

SynchronousNo
BubblesNo
CancelableNo

Event handler parameters

This method has no parameters.

Standards information

There are no standards that apply here.

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
readyState

 

 

Send comments about this topic to Microsoft

Build date: 11/29/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.