Answers for "how to set request to no cors"

1

how to set the request's mode to 'no-cors' javascript

const url = 'https://www. yammer.com/api/v1/messages/following.json';

const options = {
  method: 'GET',
  mode: 'no-cors',
  headers: {
    'Authorization': `Bearer ${process.env.REACT_APP_YAMMER_ACCESS_TOKEN}`,
  }
};

fetch(url, options).then(function(response) {
  console.log(response);
  return response.json();
}).then(function(json) {
  console.log(json);
});
Posted by: Guest on August-19-2021
4

Add no cores to fetch

// There were no quick access to mode and credentials to other fetch answers.
// Data you'll be sending
const data = { funny: "Absolutely not", educational: "yas" }

fetch('https://example.com/api/', {
  method: 'POST', // The method
  mode: 'no-cors', // It can be no-cors, cors, same-origin
  credentials: 'same-origin', // It can be include, same-origin, omit
  headers: {
    'Content-Type': 'application/json', // Your headers
  },
  body: JSON.stringify(data),
}).then(returnedData => {
  // Do whatever with returnedData
}).catch(err => {
  // In case it errors.
})
Posted by: Guest on December-14-2020
0

redirect to website from promise value fetch

fetch("http://example.com/", {
	method: 'POST',
	mode: 'cors',
	body: formData
})
.then(dataWrappedByPromise => dataWrappedByPromise.text())
.then(data => {
	//Redirect is the URL inside the text of the response promise
	window.location.replace(data);
})
Posted by: Guest on May-14-2020
0

no cors

- this repo shows how to handle the issue in 2 steps
https://github.com/Juan321654/no-cors-anywhere-package
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language