Microsoft XML 2.5 SDK


 

onreadystatechange Property

[This is preliminary documentation and subject to change.]

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

Syntax

objXMLDOMDocument.onreadystatechange = value

Remarks

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

This member is an extension of the W3C DOM.

Examples

The following JScript/HTML example specifies the handler CheckState gets called when the readyState property changes:

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

Similarly, the following example specifies the the handler HandleStateChange gets called when an XMLHTTP object's readyState property changes. A button on a page is enabled when readyState indicates that all data has been received (readystate == 4):

<script>
var xmlhttp=null;
function PostOrder(xmldoc)
{
  varxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.Open("POST", "http://myserver/orders/processorder.asp", false); 
  xmlhttp.onreadystatechange= HandleStateChange;
  xmlhttp.Send(xmldoc);
  myButton.disabled = true;
}
function HandleStateChange()
{
  if (xmlhttp.readyState == 4)
  {
    myButton.disabled = false;
    alert("Result = " + xmlhttp.responseXML.xml);
  }
}
</script>

In Visual Basic, you can get a function pointer using the syntax getRef("HandleStateChange").

Applies To

XMLDOMDocument, XMLHTTPRequest