Basic knowledge of HTTP messages and ajax,
HTTP packets
The content that the client sends to the server and the content that the server sends to the client belong to the HTTP packet.
Start row: the start row of the request's start row.
Header: Request Header Response Header General header (both request and response) custom Header
Body: Request body response body
The client transmits data to the server:
The request URL is followed by a question mark to pass the parameter to the server/getList? Name = zhangsan & age = 7
Set the Request Header (Set Request Header Information)
Set the Request body and place the content passed to the server in the Request body and send it to the server.
The server sends the data to the client:
Set response header information
Set response body content
Ajax: async javascript and xml asynchronous JS and XML (eXtensible Markup Language, the labels used in XML files are all self-extended, store related data using its own extended, rule-based tags)
Ajax is a method in client JS used to send requests to the server (or to transmit data to the server ), then obtain the content returned by the server (Ajax is generally run in the browser of the client ).
Ajax Step 4:
Create an Ajax object (this method is not supported in IE6 and earlier browsers)
var xhr = new XMLHttpRequest;
Configure basic information before sending: configure the Request Method (GET, POST, PUT, DELETE, HEAD ...)
Open a URL (Configure which server address to send a request)
Synchronous or asynchronous (true indicates asynchronous false indicates that the default value of synchronization is true)
[Username] user name for the request to the server
[Userpass] the user password for the request to the server. These two values are generally not written. Only when the server imposes security restrictions and only allows access by specific users can we pass them through.
xhr.open('get',"/data.txt",false,[username],[userpass]);
Bind a method to the onreadystatechange event to listen for changes in the status (trigger method execution as long as the status changes)
xhr.onreadystatechange = function(){
Xhr. readyState: AJAX status code, which can represent the progress of the current processing
0 unset the current request has not been sent
1. The opened URL address is enabled (the parameter configuration before sending is complete)
2. The headers_received response header is accepted.
3. The content returned by loading is being prepared on the server.
4. The done response body has been successfully returned to the client.
Xhr. status: HTTP Network status Code, which describes the status of the server response content
200 OR ^ 2 \ d {2} (200 OR starts with 2)-> indicates that the content of the response body has been successfully returned.
301 permanent redirect/permanent transfer
302 temporary redirection/Server Load balancer for temporary transfer
304 The retrieved content is to read the data in the cache.
400 An error occurred while passing parameters from the client to the server.
401 no access permission
404 The client access address does not exist
500 Unknown Server Error
503 the server is overloaded
if(xhr.readyState===4 && /^2\d{2}$/.test(xhr.status)){ var val = xhr.responseText; }}
Send request: the parameter is the content transmitted to the server by the request body.
xhr.send(null);
Summary
The above section describes the basic knowledge of HTTP messages and ajax. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!