Microsoft XML SDK 2.6 - XML Reference

onreadystatechange Event

Indicates when the readyState property changes.

Inline HTML
<ELEMENT onreadystatechange = "handler" ... >
All platforms
Event property
object.onreadystatechange = handler
JScript (compatible with ECMA 262 language specification) only
Named script
<SCRIPT FOR = object EVENT = onreadystatechange>
Internet Explorer only

Remarks

This event can be explicitly set using the onreadystatechange property.

This member is an extension of the W3C DOM.

Example

The following JScript/HTML example demonstrates the sequence of ready states when asynchronously loading a document:

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

The following Visual Basic example shows how to use the onreadystatechange event in an application:

Dim WithEvents xmldoc As DOMDocument

Private Sub Form_Load()
    Set xmldoc = New DOMDocument 
    xmldoc.Load ("http://xmlweb/msxml/jscript/error.xml")
End Sub

Private Sub xmldoc_onreadystatechange()
    If (xmldoc.readyState = 4) Then 
      msg = "Load  is finished" & Chr(13) 
      If (xmldoc.parseError.errorCode <> 0) Then
        msg = msg + "Error: " & xmldoc.parseError.reason
      End If
      MsgBox msg
    End If
End Sub

See Also

Applies To: DOMDocument Object