Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between readyState and status in AJAX

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the difference between readyState and status in AJAX". In daily operation, I believe that many people have doubts about the difference between readyState and status in AJAX. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the difference between readyState and status in AJAX?" Next, please follow the editor to study!

Look at the code first.

This code constructs an instance of the XHR object, request, and uses it to create asynchronous requests. In the onreadystatechange event, we found that there are two attributes, readyState and status, where readyState gets the AJAX status value, which has the following meaning:

0: the request is not initialized and the open method has not been called

1: the server connection has been established and open has called

2: the request has been accepted, that is, the header message has been received

3: in the process of request processing, the response subject is received

4: request completion, that is, response completion

Status gets the HTTP status code, which consists of three digits, with the first digit and meaning as follows:

1xx: indicates that the server has received a request from a web browser and is processing

2xx: successful, indicating that the user's request is correctly accepted, understood and processed

3xx: redirect, indicating that the request was not successful and the customer needs to take further action

4xx: client error, indicating that the request submitted by the client is incorrect

5xx: server error, indicating that the server cannot complete the processing of the request

So what is the difference and relationship between the AJAX status value and the HTTP status code? This is a question worth thinking about, although it is of no use to programming itself, but it is more important to know why, let's study it.

As we all know, the core of AJAX is the XHR object. During the execution of AJAX, the value of readyState changes from 0. When AJAX runs to the send method call, the HTTP request is sent, and the HTTP request installation step is executed. At this time, the value of status begins to change, and the AJAX running mechanism waits for the HTTP request to return the result. Finally, when the HTTP request returns a result, regardless of whether the HTTP request succeeds or fails, and whether or not the correct information is requested, the running mechanism of the AJAX continues to execute until it finishes running or an error occurs. This is my understanding of the relationship between AJAX status values and HTTP status codes.

At this point, the study on "what is the difference between readyState and status in AJAX" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report