XMLHttpRequest two important ways to send requests:
Open (Method,url,async)--Parameters: Request mode, request address, request synchronous/asynchronous;
Send (String)--parameter: Fill in this parameter when using post mode.
Usage examples:
Request.open ("POST", "create.php", true);
Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); To write between open and send
Request.send ("Name= Zhang San &sex= male");
XMLHttpRequest gets several important properties and methods of the response:
Reponsetext: Getting response data in string form
Reponsexml: Getting response data in XML form
Status and StatusText: Returns the HTTP status code in numeric and textual form
Getallreponseheader (): Gets all the response headers
getResponseHeader (): Gets the value of a field in the response
The change in the ReadyState property represents a change in the server response:
0: Request uninitialized, Open has not been called
1: The server connection has been established and open has been called
2: The request has been received, that is to receive the header information
3: The request is processed, that is, the response body is received
4: The request is complete and the response is ready, that is, the response is complete
Tips:
Use the onReadyStateChange event to listen for HTTP request processing,
When Readystate===4 && status===200 indicates that the response is complete and the request is successful,
So that we can use the data obtained from the background to do the corresponding operation.
XMLHttpRequest Basic Knowledge