fetch follow redirect code example
Example 1: fetch api javascript
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});
Example 2: fetch suntax
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
Example 3: redirect to website from promise value fetch
fetch("http://example.com/", {
method: 'POST',
mode: 'cors',
body: formData
})
.then(dataWrappedByPromise => dataWrappedByPromise.text())
.then(data => {
window.location.replace(data);
})