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
35

js fetch 'post' json

//Obj of data to send in future like a dummyDb
const data = { username: 'example' };

//POST request with body equal on data in JSON format
fetch('https://example.com/profile', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then((response) => response.json())
//Then with the data from the response in JSON...
.then((data) => {
  console.log('Success:', data);
})
//Then with the error genereted...
.catch((error) => {
  console.error('Error:', error);
});

//																		Yeah
Posted by: Guest on March-28-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