The Fetch class provides a way to make asynchronous network requests, typically to retrieve resources from a server.
var fetchApi = new Fetch('index.html', 'GET');
fetchApi.send()
.then((value) => {
console.log(value);
}).catch((error) => {
console.log(error);
});
string
Specifies the content type of the request, which is used to indicate the original media type of the resource.
Defaults to null
string
| Object
Specifies the data that needs to be added to the request.
Defaults to null
Request
Specifies the request object that represents a resource request.
Defaults to null
string
Specifies which request method is to be used, such as GET, POST, etc.
Defaults to GET
string
Specifies the URL to which the request is to be sent.
Defaults to null
Send the request to server.
Parameter | Type | Description |
---|---|---|
data (optional) | string | Object |
Specifies the data that needs to be added to the request. |
Returns Promise
Function
Specifies the callback function to be triggered before sending the request to the server. This can be used to modify the fetchRequest object before it is sent.
Function
Specifies the callback function to be triggered after the request is failed.
Function
Specifies the callback function to be triggered after the response is received. This callback will be triggered even if the request is failed.
Function
Specifies the callback function to be triggered after the request is successful. The callback will contain the server response as a parameter.