This is the 16th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021
preface
In the last few articles, we’ve learned how to document JavaScript in the browser.
After learning the FETCH network request method in the beginning, this article will continue to learn other details about the network: HTTP response code (i.e. status code)
HTTP response code
The response data of the last FETCH request is judged by the returned status code to determine whether the correct data is returned. The return to normal state is status 200
The HTTP response status code indicates whether a particular HTTP request has completed successfully. Responses fall into five categories: message response (100-199), success response (200-299), redirection (300-399), client error (400-499), and server error (500-599).
There are many HTTP status codes, such as 200, 304 and so on, which are often used in work, and are often asked in interviews. The following describes the common HTTP status codes:
Common status codes
Open the console in Chrome and refresh the page in the Network option to see the various requests and their status.
In fact, if the network is good, in the console generally see the following code, such as the home page of this site is only two
-
200 OK request successful!
-
204 No Content The server successfully processed the request, but does not need to return any physical Content and wants to return updated meta-information. The response may return new or updated meta information in the form of entity headers.
HTTP response code classification
The message response starts with 1, and so on
-
Information response
-
The request is successful
-
Redirect (304).
304 Not Modified – The server should return this status code if the client has sent a conditional GET request and the request has been granted, and the contents of the document have Not changed (since the last access or according to the conditions of the request)
-
Client Response (403/404)
401 Unauthorized – The current request requires user authentication. The response must include a WWW-Authenticate header applicable to the requested resource to ask for user information
403 Forbidden – The server understands the request but refuses to execute it. Unlike the 401 response, authentication does not help
404 Not Found – The requested resource failed to be Found on the server.
-
Server Response (500/502)
500 Internal Server Error – The Server encountered a situation that it did not know how to handle.
502 Bad Gateway – This error response indicates that the server acting as the Gateway needs to get a response to process this request, but gets an incorrect response
Read more about it
- -number – This is a function
- Automatic type conversion
- Infix operators in JavaScript
- Do you know what JavaScript Typeof is?
- Learn a few representative events in JavaScript
- Learn to Understand client-side JavaScript- Event Classification (part 1)
- Client-side JavaScript- Event Classification (2)
- Learn to understand JavaScript events and event loops
- Understand JavaScript in the browser – event registration
- The javascript-fetch () network request method in the browser
- # fetch request response processing display
Calm Down & Carry On!
Buy Less by Know More! Come on!
Learning, recording and accumulating is a long process!
Refer to the content
- | MDN network – the HTTP response code