Click to Rate and Give Feedback
MSDN
MSDN Library

  Switch on low bandwidth view
onreadystatechange Property

Sets or retrieves the event handler for asynchronous requests.

Syntax

[ vHandler = ] object.onreadystatechange [ = v ]

Possible Values

vHandlerVariant that specifies or receives the event handler.

The property is read/write. The property has no default value.

Remarks

onreadystatechange was introduced in Windows Internet Explorer 7.

Example

The following script demonstrates how to set an event handler that responds to asynchronous events:

function reportStatus()
{
    if (oReq.readyState == 4)
        alert('Transfer complete.');
}

var oReq = new XMLHttpRequest();
oReq.onreadystatechange = reportStatus;
oReq.open("GET", "http://localhost/test.xml", true);
oReq.send();

Standards Information

This property is defined in The XMLHttpRequest Object (W3C Working Draft) World Wide Web link.

Applies To

XMLHttpRequest, XMLHttpRequest Constructor

See Also

readyState
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
In my opinion, attachEvent should be able to be used on XMLHttpRequest object      pbnec   |   Edit   |   Show History
onreadystatechange is really only a property of XMLHttpRequest object. Therefore, You CANNOT use attachEvent on the object... (In my opinion, onreadystatechange should have something similar to e.g. onload property of window object...)
Probable bug with onreadystatechange      mrezair ... nico kooijman   |   Edit   |   Show History


Hi:

I am also have a problem with onreadystatechange .

here is the code below i am using:

<script>

var req;

var which;

function fetchCorpClassTaxonomy(url) {

alert("entered into Ajax function");

if (window.XMLHttpRequest) { // Non-IE browsers

alert("NON IE Block is Invoked");

req = new XMLHttpRequest();

req.onreadystatechange = processStateChange;

try {

req.open("GET", url, true);

} catch (e) {

alert(e);

}

req.send(null);

} else if (window.ActiveXObject) { // IE

alert("entered into IE block");

req = new ActiveXObject("Microsoft.XMLHTTP");

if (req) {

alert("entered into if(req)");

req.onreadystatechange = processStateChange;

req.open("GET", url, true);

alert("readystate: "+ req.readyState);

req.send();

}

}

}

function processStateChange() {

alert("entered into processStateChange()");

if (req.readyState == 4) { // Complete

if (req.status == 200) { // OK response

alert("response received from server is "+req.responseText);

var serverResponse = req.responseText;

var fieldName = serverResponse.substring(0,serverResponse.indexOf ("|"));

//alert("fieldname string "+fieldName);

var restResponse = serverResponse.substring(serverResponse.indexOf ("|")+1,serverResponse.length);

//alert("rest of Response is "+restResponse);

if(fieldName == "classification"){

document.getElementById("subclassification").innerHTML = restResponse;

}

} else {

alert("Problem: " + req.statusText);

}

}

}


The function processStateChange() is not called.

what might be the problem..

Please give me your valuable suggestion as soon as possible.

Thanks.....

++++++++++++++++++++++++++++++++++++++++++++++++

function reportStatus()
{
    if (oReq.readyState == 4)
        alert('Transfer complete.');
}

var oReq = new XMLHttpRequest();
oReq.onreadystatechange = reportStatus;
oReq.open("GET", "http://localhost/test.xml", true);
oReq.send();

I think you are using the "old" version of req = new ActiveXObject("Microsoft.XMLHTTP");
It will work if you specify var req = new XMLHttpRequest();

Better add random number      pedro_t   |   Edit   |   Show History
problem with this is that when the page is reloaded, the counter resets and the same problem occurs. It might be a better idea to add a large randomized number that has a tiny chance of reoccurring.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker