0

In my code I refer to an API using the following

fetch('https://?....).then(response => {
                        return response.json();

However I have a requirement to pass in a local file (JSON) instead of the api url as below

fetch('file:///E:/testData.json')

I get the error "URL scheme must be "http" or "https" for CORS request"

Would really appreciate if someone can point me the right direction here. How can I parse a local JSON in this case ? what am i doing wrong here

dev_tech
  • 43
  • 6
  • Does this answer your question? [Disable same origin policy in Chrome](https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome) – Joundill Jan 14 '21 at 20:07

1 Answers1

0

you need to create the folder with json file in your project and call in this mode:

fetch('./api/some.json')
  .then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        console.log(data);
      });
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });
corsaro
  • 537
  • 1
  • 5
  • 19