onreadystatechange Property (DOMDocument)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

onreadystatechange Property (DOMDocument)

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

[Script]

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 ActiveXObject5.0("Msxml2.DOMDocument.5.0");
   xmldoc.onreadystatechange = CheckState;
   xmldoc.load(URL.value);
   if (xmlDoc.parseError.errorCode != 0) {
      var myErr = xmlDoc.parseError;
      alert("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> 

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

[Visual Basic]

Visual Basic Syntax

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

Example

The following Microsoft Visual Basic example specifies the handler CheckState gets called when the readyState property changes.

Private WithEvents XmlDoc As Msxml2.DOMDocument50
Private Sub cmdEvents_Click()
   Set XmlDoc = New Msxml2.DOMDocument50
   XmlDoc.Load "books.xml"
   If (xmlDoc.parseError.errorCode <> 0) Then
      Dim myErr
      Set myErr = xmlDoc.parseError
      MsgBox("You have error " & myErr.reason)
   End If
End Sub
Private Sub XmlDoc_onreadystatechange()
    MsgBox "onreadystatechange: " & XmlDoc.readyState
End Sub 
[C/C++]

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

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

onreadystatechange Event | readyState Property

Applies to: DOMDocument