onreadystatechange event
Sets or retrieves the event handler for asynchronous requests.
Syntax
| HTML Attribute | <element onreadystatechange = "handler(event)"> |
|---|---|
| attachEvent Method | object.attachEvent("onreadystatechange", handler) |
Event information
| Synchronous | No |
|---|---|
| Bubbles | No |
| Cancelable | No |
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