Knowledge preparation: Method XHR. readyState five States XHR. readyState state (, 4) 0: the request has not been initialized and open () has not been called (). 1: The request has been created, but has not been sent yet. send () has not been called (). 2: The request has been sent and is being processed (the content header can be obtained from the response ). 3: request in
Knowledge preparation: Method XHR. readyState five States XHR. readyState = status (, 4) 0: the request is not initialized and open () has not been called (). 1: The request has been created, but has not been sent yet. send () has not been called (). 2: The request has been sent and is being processed (the content header can be obtained from the response ). 3: request in
Knowledge preparation:
Method XHR. readyState
XHR. readyState = status (0, 1, 2, 3, 4)
0: the request has not been initialized and open () has not been called ().
1: The request has been created, but has not been sent yet. send () has not been called ().
2: The request has been sent and is being processed (the content header can be obtained from the response ).
3: The request is being processed. Generally, some data in the response is available, but not all of the data is completed.
4: The response has been completed. You can obtain and use the server response.
Methods Common statuses of XHR. status
XHR. status = 200,300,404, etc.
100 -- the customer must continue to send the request
101 -- the client requests the server to convert the HTTP protocol version according to the request
200 -- successful
201 -- prompt to know the URL of the new file
300 -- the requested resources can be obtained in multiple places
301 -- Delete request data
404 -- no file, query, or URl found
500 -- Internal error occurred on the server
Principle of creating a progress bar:
You can use XHR. readyState = 1 to determine whether a progress bar is displayed. Use XHR. readyState = 4 and XHR. status = 200 to determine whether the server has successfully completed the response.
Instance code:
(The code is partially modified according to the previous example. For details, refer to: Ajax + PHP Quick Start and simple application)
Index.html