0% found this document useful (0 votes)
117 views1 page

Guide - Fetch

The Fetch API provides a JavaScript interface for making asynchronous HTTP requests. It provides a global fetch() method that streamlines accessing and fetching resources across the network, which was previously done less conveniently using XMLHttpRequest. Fetch also serves as a single standard place to define other HTTP concepts and allows technologies like Service Workers to more easily make requests. An example demonstrates using fetch to make a POST request with JSON data and handle the response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views1 page

Guide - Fetch

The Fetch API provides a JavaScript interface for making asynchronous HTTP requests. It provides a global fetch() method that streamlines accessing and fetching resources across the network, which was previously done less conveniently using XMLHttpRequest. Fetch also serves as a single standard place to define other HTTP concepts and allows technologies like Service Workers to more easily make requests. An example demonstrates using fetch to make a POST request with JSON data and handle the response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Fetch

Intro

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and
responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the
network.

This kind of functionality was previously achieved using XMLHttpRequest. Fetch provides a better alternative that can be easily
used by other technologies such as Service Workers. Fetch also provides a single logical place to define other HTTP-related
concepts such as CORS and extensions to HTTP.

function request_nse_element(){
let career_credit = {{ credit.id }};
let url = `/personal/credit/${career_credit}/parametrics/nse/`;
let data = {};
fetch(url, {
csrfmiddlewaretoken: "{{ csrf_token }}",
method: 'POST', // or 'PUT'
body: JSON.stringify(data), // data can be `string` or {object}!
headers:{
'Content-Type': 'application/json',
'X-CSRFToken': getCookie('csrftoken')
}
}).then(res => res.json())
.catch(() => {
document.getElementById("parametric_nse").innerHTML = "<p>Hubo un Error</p>";
})
.then(response => {
document.getElementById("parametric_nse").innerHTML = response.content;
});
}

You might also like