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++.
Script Syntax
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>
Note
In Microsoft Visual Basic® Scripting Edition (VBScript), you can get a function pointer using the syntax getRef("HandleStateChange")
.
Visual Basic Syntax
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
See Use OnReadyStateChange Property in Visual Basic and Visual C/C++.
C/C++ Syntax
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
See Use OnReadyStateChange Property in Visual Basic and Visual C/C++.
Remarks
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).
Versioning
Implemented in: MSXML 3.0, MSXML 6.0