0

I am having issues fetching data from an api from the client side. I have verified that you can get data from the api in node.js, python and by going to the url but I get an error when trying to access it from the client.

function fetchData(url) {
  return fetch(url)
    .then((res) => {return res.text()})
    .catch((err) => console.log(err));
}

fetchData("Some url string").then((data) => console.log(data));

In node.js this allows me to get the response data but on the client page this returns an error.

  • Only use `no-cors` if you want an opaque response. If you actually want a response, don't use `no-cors` – CertainPerformance Sep 10 '20 at 03:50
  • How are you trying to display the data on the client? – Abdel P. Sep 10 '20 at 03:51
  • When I get rid of no-cors: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. – Aidan Paetsch Sep 10 '20 at 03:58

0 Answers0