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;
The following script example specifies the handler HandleStateChange gets 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 ActiveXObject5.0("Msxml2.XMLHTTP.5.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;
alert("Result = " + xmlhttp.responseXML.xml);
}
}
</script>
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 DOMDocument50
See Use OnReadyStateChange Property in Visual Basic and Visual C/C++.
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.
readyState property value changes.See Use OnReadyStateChange Property in Visual Basic and Visual C/C++.
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).
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.
Applies to: IXMLHTTPRequest