Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

onreadystatechange Property (IXMLHTTPRequest)

Specifies the event handler to be called when the readyState property changes. Note that onreadystatechange is designed for use in scripting environments and is not readily accessible in Microsoft® Visual Basic® or C++.

oXMLHttpRequest.onreadystatechange = funcMyHandler;

Example

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

<script>
var xmlhttp=null;
function PostOrder(xmldoc)
{
  var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
  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;
    WScript.Echo("Result = " + xmlhttp.responseXML.xml);
  }
}
</script>


NoteNote

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

In Visual Basic, you need to write the following statement where xmldoc is a variable and implements a subroutine called xmldoc_onreadystatechange().

Dim WithEvents xmldoc As DOMDocument30

Example

Use connection points to trap readystatechange events.

The following macros declare the handler (DOMDocCheckState) for the event:

BEGIN_DISPATCH_MAP(CXMLDOMSamples, CCmdTarget)
   DISP_FUNCTION_ID(CXMLDOMSamples, "Ready State Event Handler", 
   DISPID_XMLDOMEVENT_ONREADYSTATECHANGE, DOMDocCheckState, VT_EMPTY, 0)
END_DISPATCH_MAP()
"m_hr = pCP->Advise(GetIDispatch(TRUE), &m_pdwCookie); " 

The last line registers this class (CXMLDOMSamples) as an event listener with the document Connection Point Container. 

Parameters

pReadyStateSink[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.

Example

The property is write-only. When using scripting languages, this property can be set in ways other than directly accessing the property through IXMLHTTPRequest. 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 World Wide Web Consortium (W3C) Document Object Model (DOM).

Implemented in: MSXML 3.0, MSXML 6.0

Show:
© 2014 Microsoft