1.1 My understanding:
- Every time a user operates, data will be generated.
- passDOMorJSWrite to encapsulate the data, or the browser itselfhttpSome data from the protocol is encapsulated.
- passxmlHttpSome methods of the object, passing in data parameters,httpThe server sends a request.
- Return result passedDOMPerform processing.
2 xmlHttpMember of the object.
2.1 property
- onreadystatechange:whenreadyStateThe event processing handle triggered when the property value changes.
example: = functionHandler;
function functionHandler() {
if( == 4) {
alert("whenreadyStateStatus is4When this window pops up! ! !");
}
}
//The handle has only method name, no this pair()”Branch. Pay attention to understanding when assigning values.
- readyState:This attribute represents a state; there are five states in total:
0 (not initialized) |
The object has been established, but has not been initialized (the open method has not been called yet) |
1 (Initialization) |
The object has been created and the send method has not been called yet |
2 (Send data) |
The send method has been called, but the current status and http header are unknown |
3 (Data transmission) |
Some data has been received, because the response and http headers are incomplete, an error will occur when a responseBody and responseText is obtained. |
4 (Complete) |
After the data is received, you can obtain the complete response data through responseBody and responseText. |
// becausexmlHttpThe writing method is fixed, so each step will be accompanied by a change in state, so the event processing handle is always listened to and the corresponding logic is executed.
Code execution order:
var xmlHttpReq = new ActiveXObject(".3.0");
("GET", "http://localhost/", false);
();
alert();
2.2 method
- open(Method, Url, Syn, User, Password);
Create a newxmlHttpWhen an object is created, it is actuallyhttpask.
This method specifies the requested method(GET/POST/PUT/PROPFIND)、 URL,asynchronous(The default istrue), verification information.
Adopt asynchronous(true)When the state changes, it will be calledThe callback function specified by the onreadystatechange property.
- send();
The synchronous or asynchronous way of this method depends on the open methodSyn parameter, ifSyn == false, this method will wait for the request to complete or timeout before returning, ifSyn == true, this method will return immediately.