A preliminary understanding of Ajax and talk about their basic knowledge
1. Instantiate the XHR object
var request=new XHLHttpRequest Because of compatibility issues, it is generally written like this: var request; if (window.XHLHttpRequest){ request=new XMLHttpRequest();//IE7+ }else{ request=newActiveXObject("Microsoft.XMLHttp"); }
2. HTTP request
1) The method or action of the HTTP request
1>get request: generally used for information acquisition
use url to pass parameters
There is also a limit to the number of messages sent, generally within 2000 characters
2>POST request: modify server resources
Unlimited number of messages sent
3. Response status code
The http status code consists of 3 digits, the first digit defines the status code type
1xx: Information class, indicating that a web browser request has been received and is being further processed
2xx: success
3xx: Redirect, indicating that the request was not successful and the client must take further action
4xx: Client error, indicating that the request submitted by the client is wrong
5xx: Server error, indicating that the server cannot complete the processing of the request
4. XMLHttpRequest gets the response
.responseText: Get response data of string type
.responseXML: Get response data in XML form
status and status Test: Return HTTP status codes as numbers and text
getAllReponseHeader(): Get all response headers
getResponseHeader(): The value of a field in the query response
5.readystate property
0: The request is not initialized, OPEN has not been called
1: The server link has been established, and OPEN has been called
2: The request has been accepted, that is, the header information has been received
3: The request is being processed, that is, the body of the response has been received
4: The request is complete, the response is ready
6. Ajax GET request
xmlhttp.open("GET","doem_get_asp",true);
xmlhttp.send()
7. Ajax POST request
xmlhttp.open("POST","dome_post_asp",true);
xmlhttp.send()