Microsoft XML SDK 2.6 - XML Reference

onreadystatechange Property (XMLHttpRequest)

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

objXMLHttpRequest.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 XMLHttpRequest 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.

Example

The following JScript/HTML example specifies the the handler HandleStateChange gets called when an XMLHttpRequest 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)
{
  var xmlhttp = new ActiveXObject("Msxml2.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 VBScript, you can get a function pointer using the syntax getRef("HandleStateChange").

See Also

Applies To: XMLHttpRequest Object