onreadystatechange Property (DOMDocument)

 

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

Script Syntax

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

Example

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

<script>
var xmldoc;
function Load(){
   xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
   xmldoc.onreadystatechange = CheckState;
   xmldoc.load(URL.value);
   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>"
  } 
} 
</script>
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>

Note

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

Visual Basic Syntax

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

C/C++ Syntax

HRESULT put_onreadystatechange(  
    VARIANT readystatechangeSink);  

Parameters

readystatechangeSink[in]
Name of the function that should be called when the readyState property value changes.

C/C++ Return Values

S_OK
Value returned if successful.

Remarks

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).

Versioning

Implemented in:

MSXML 3.0, MSXML 6.0

Applies to

IXMLDOMDocument-DOMDocument

See Also

onreadystatechange Event
readyState Property (DOMDocument)