In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use fetch API". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use fetch API.
FetchAPI provides an interface to get resources (including cross-domain requests). Anyone who has ever used XMLHttpRequest can easily get started, and the new API provides a more powerful and flexible feature set.
The concept and usage of FetchAPI
Fetch provides a general definition of Request and Response (and other objects related to network requests). So that it can be used in more application scenarios in the future: whether it's serviceworker, CacheAPI, or other ways to handle requests and responses, or even any way you need to generate your own responses in the program.
It also provides a new definition for concepts related to connectedness, such as CORS and HTTP native header information, replacing their original separate definitions.
You need to use the WindowOrWorkerGlobalScope.fetch () method to send a request or get a resource. It is implemented in many interfaces, more specifically, on the Window and WorkerGlobalScope interfaces. Therefore, resources can be obtained in this way in almost all environments.
Fetch () must accept one parameter-- the path to the resource. Whether the request is successful or not, it returns a Promise object, and the resolve corresponds to the Response of the request. You can also pass an optional second parameter, init (see Request).
Once the Response is returned, you can use some methods to define the form of the content and how it should be handled (see Body).
You can also create requests and responses directly through the constructors of Request () and Response (), but we do not recommend this. They should be used to create other API results (for example, FetchEvent.respondWith in serviceworkers).
What does FetchAPI need to know?
Note: for more information on the use of FetchAPI, refer to UsingFetch, as well as some concepts Fetchbasicconcepts.
Abort fetch
Browsers have begun to add experimental support to the AbortController and AbortSignal interfaces (that is, AbortAPI), allowing operations such as Fetch and XHR to be aborted before they are completed. Please refer to the interface page for more details.
Fetch interface
WindowOrWorkerGlobalScope.fetch ()
Contains the fetch () method, which is used to get resources.
Headers
Equivalent to the header information of response/request, you can query these headers or do different operations for different results.
Request
Is equivalent to a resource request.
Response
Equivalent to a response to a request
At this point, I believe you have a deeper understanding of "how to use fetch API". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.