AjaxArticle
XMLDocumentAnd XMLHttpRequestObject
1. Create an XMLHttpRequest request objectCopy to Clipboard reference content: [www.bkjia.com] function getXMLHttpRequest (){
Var xRequest = null;
If (window. XMLHttpRequest ){
XRequest = new XMLHttpRequest ();
} Else if (typeof ActiveXObject! = "Undefined "){
XRequest = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Return xRequest;
}
Or:
Copy to ClipboardReference: [www.bkjia.com] var request = null;
Function createRequest (){
Try {
Request = new XMLHttpRequest (); // non-Microsoft IE browser
} Catch (trymicrosoft) {// Microsoft IE
Try {
Request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (othermicrosoft ){
Try {
Request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (failed ){
Request = null;
}
}
}
If (request = null)
Alert ("Error creating request object !");
}
This independent function for creating the XMLHttpRequest request object can be called.
Note:: XMlHTTP objects are not W3C standards. Therefore, you must consider the support of different browser environments when creating them.
The XMLHTTP object has 6 methods and 8 attributes. It supports two execution modes: synchronous and asynchronous.
XMLHTTP objectAttributeAndMethodList (from IXMLHTTPRequest Interface ):
|
Attribute name |
Type |
Description |
|
Onreadystatechange |
N/ |
Specifies the event processing function called when the ready status changes. It is only used for asynchronous operations. |
|
ReadyState |
Long |
Asynchronous Operation Status: Not initialized (0), loading (1), loaded (2), InterAction (3), completed (4) |
|
ResponseBody |
Variant |
Returns the response body as an unsigned byte array. |
|
ResponseStream |
Variant |
Returns the response body as an ADO Stream object. |
|
ResponseText |
String |
Returns the response body as a text string. |
|
ResponseXML |
Object |
Resolve the response body to an XMLDocument object through XMLDom |
|
Status |
Long |
HTTP status code returned by the server |
|
StatusText |
String |
Server HTTP Response line status |
|
Method Name |
Description |
|
Abort |
Cancel current HTTP Request |
|
GetAllResponseHeaders |
Retrieve all header fields from the response information |
|
GetResponseHeader |
Obtain an HTTP header field value from the response body. |
|
Open (method, url, boolAsync, bstrUser, bstrPassword) |
Open a connection to the HTTP server |
|
Send (varBody) |
Send a request to the HTTP server. Body. |
|
SetRequestHeader (bstrHeader, bstrValue) |
Set the header field of a request |
- Four pages in total:
- Previous Page
- 1
- 2
- 3
- 4
- Next Page