Difference and connection between readyState and status in jQuery AJAX, jqueryreadystate

Source: Internet
Author: User

Difference and connection between readyState and status in jQuery AJAX, jqueryreadystate

The emergence of AJAX, one of the web Front-end kicker, subverts many people's understanding of the web Front-end. From my perspective, if the three html/css/Javascript artifacts were finally integrated in 1996, and the web Front-end was able to summon X-Dragon, ajax was the first X-Dragon summoned by the three artifacts. Since then, the front-end code is completely separated. When you encounter problems such as passing parameters to the background, front-end programmers can confidently shout out: please wait for me to wait until then .....

When using AJAX, I use native js instead of jQuery and other frameworks here, because the Queen tells us that native is the most powerful ....

Let's not talk much about it. Let's look at the code first.

 

This code constructs an XHR object instance request and uses it to create an asynchronous request. In the onreadystatechange event, we found that there are two attributes: readyState and status. The value and meaning of readyState are as follows:

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

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

2: The request is accepted, that is, the header information is received.

3: The request is being processed, that is, the response body is received.

4: The request is complete, that is, the response is complete.

Status indicates the HTTP status code, which consists of three digits. the first digit and meaning are as follows:

1xx: the server receives a request from the web browser and is processing the request.

2xx: Successful, indicating that the user request is correctly accepted, understood, and processed

3xx: Redirection, indicating that the request failed. The customer needs to take further actions

4xx: client error, indicating a request error submitted by the client

5xx: server error, indicating that the server cannot process the request

So what is the difference and connection between AJAX Status values and HTTP status codes? This is a question worth thinking about. Although it is useless to programming itself, we will continue to study it by knowing its truth.

As we all know, the core of AJAX is the XHR object. During AJAX execution, the value of readyState changes from 0. When AJAX runs to the send method call, it sends an HTTP request, when the HTTP request installation step is executed, the status value changes. The AJAX Running Mechanism waits for the HTTP request to return the result. Finally, after an HTTP request returns a result, no matter whether the HTTP request is successful or failed, or whether the request is correct or not, the AJAX running mechanism will continue to execute until the operation is completed or an error occurs. This is the relationship between AJAX Status values and HTTP status codes that I understand.
I don't know if this is acceptable to everyone. If you have any unclear or wrong information, please comment out in the comment area. Aliga-do.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.