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.
<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")
.
Private WithEvents XmlDoc As Msxml2.DOMDocument Private Sub XmlDoc_onreadystatechange()
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
HRESULT put_onreadystatechange( VARIANT readystatechangeSink);
readyState
property value changes.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 in the upper-left corner of the page.
onreadystatechange Event | readyState Property
Applies to: DOMDocument