onreadystatechange Property (DOMDocument)


Specifies the event handler to be called when the readyState property changes.

oXMLDOMDocument.onreadystatechange = funcMyEventHandler;  
objXMLDOMDocument.onreadystatechange = value;  


The following script example specifies the handler CheckState gets called when the readyState property changes.

var xmldoc;
function Load(){
   xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
   xmldoc.onreadystatechange = CheckState;
   if (xmlDoc.parseError.errorCode != 0) {
      var myErr = xmlDoc.parseError;
      WScript.Echo("You have error " + myErr.reason);
function CheckState(){
  var state = xmldoc.readyState;
  RESULTS.innerHTML += "readyState = " + state + "<BR>"
  if (state == 4){
    var err = xmldoc.parseError;
    if (err.errorCode != 0)
      RESULTS.innerHTML += err.reason +  "<BR>"
    else RESULTS.innerHTML += "Success" +  "<BR>"
URL: <input type=text size=60 id=URL><input type=button value=LOAD onclick=jscript:Load()>
<div id=RESULTS style="color:red; font-weight:bold;"></div></script>

System_CAPS_ICON_note.jpg Note

In Microsoft® Visual Basic® Scripting Edition (VBScript), you can get a function pointer using the syntax getRef("HandleStateChange").

Private WithEvents XmlDoc As Msxml2.DOMDocument  
Private Sub XmlDoc_onreadystatechange()  

HRESULT put_onreadystatechange(  
    VARIANT readystatechangeSink);  


Name of the function that should be called when the readyState property value changes.

C/C++ Return Values

Value returned if successful.

The property is write-only. When using scripting languages, this property can be set in ways other than directly accessing the property through DOMDocument. It can also be set using the onreadystatechange attribute of the <XML> tag, and the SCRIPT FOR... construct.

You can call the QueryInterface method of the DOMDocument to obtain IConnectionPointContainer for event management. The DISPID for this event is DISPID_XMLDOMEVENT_ONREADYSTATECHANGE.

This member is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

Implemented in:

MSXML 3.0, MSXML 6.0


onreadystatechange Event
readyState Property (DOMDocument)