www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Properties
 onreadystatechange Property
onreadystatechange Property

Sets or retrieves the event handler for asynchronous requests.

Syntax

[ vHandler = ] XMLHttpRequest.onreadystatechange [ = v ]

Possible Values

vHandlerVariant that specifies or receives that specifies 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.
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

See Also

readyState
Tags What's this?: Add a tag
Community Content
 
Add Community Content
In my opinion, attachEvent should be able to be used on XMLHttpRequest object      pbnec   |   Edit   |  
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 bu with onreadystatechange      mrezair ... Noelle Mallory - MSFT   |   Edit   |  

I had a big problem with onreadystatechange because the function wouldn't be called.

The code looked like this:

http_request.open("GET","time.php",true);
http_request.send(null);
http_request.>{
.....

}

The problem was it worked only once. After trying so many things I understood the URL to http_request.open() should change everytime we call this function, otherwise it assumes the status for this call is already 4 and onreadystatechange is not called.

Then I created a dummy counter and each time changed it. It works both in IE and FireFox the same way.

http_request.open("GET","time.php?coun=" + counter,true);
counter++ ;

I initialize this counter in window.onload.

This does not make sense but seems it works. Any comments or solution?

[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.

Better add random number      pedro_t   |   Edit   |  
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
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG