1Clients can passXmlHttpObject (msxml2.xmlhttp.3.0) sends a request to the HTTP server and uses the Document Object model(DOM)Handle the response.
1.1 My understanding:
- Each operation of the user, there will be data generation.
- The DOM or JS is written to encapsulate the data, or the browser itself encapsulates some of the HTTP Protocol's data.
- send a request to the HTTP server by XmlHttp some methods of the object, passing in the data parameter .
- The returned results are processed through the DOM.
2 members of the XmlHttp object.
2.1 Property
- onReadyStateChange: the event handling handle that is triggered when the value of the ReadyState property changes.
Example:xmlhttp.onreadystatechange = Functionhandler;
function Functionhandler () {
if (xmlhttp.readystate = = 4) {
Alert (" pops up this window when the readyState status is 4!!! ");
}
}
The handle has only the method name, not the "()" bracket. Pay attention to understanding when assigning values.
- ReadyState: This attribute represents the state; there are five states in total:
0 (uninitialized) |
Object has been established, but has not yet been initialized (the open method has not been called) |
1 (initialization) |
Object has been established and the Send method has not been called |
2 (send data) |
The Send method has been invoked, but the current state and HTTP headers are unknown |
3 (in data transfer) |
Received part of the data because the response and HTTP headers are not complete, then there will be an error getting some of the data through Responsebody and ResponseText. |
4 (complete) |
When the data is received, complete response data can be obtained through responsebody and ResponseText |
because the xmlHttp is written in a fixed way, each step is accompanied by a state change, so it listens to the event handling handle at all times and executes the corresponding logic.
Code Execution Order:
var xmlhttpreq = new ActiveXObject ("msxml2.xmlhttp.3.0");
Xmlhttpreq.open ("Get", "Http://localhost/test.xml", false);
Xmlhttpreq.send ();
alert (Xmlhttpreq.responsetext);
2.2 Method
- Open (method, Url, Syn, User, Password);
When you create a new xmlHttp object, you are actually creating an http request.
This method specifies the mode of the request (Get/post/put/propfind), the URL, the asynchronous ( the default is true), and the authentication information.
When used asynchronously (true) , the callback function specified by the onReadyStateChange property is invoked when the state changes.
- Send ();
The way this method is synchronized or asynchronous depends on the S yn parameter in the open method , and if syn = = False, this method will wait for the request to complete or timeout to return if the syn = = TRue, this method will return immediately.