fetch javascript request header cookies code example
Example 1: Add no cores to fetch
const data = { funny: "Absolutely not", educational: "yas" }
fetch('https://example.com/api/', {
method: 'POST',
mode: 'no-cors',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(returnedData => {
}).catch(err => {
})
Example 2: .fetch method
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));