-2

I reckon this might be an old topic but I begin with Javascript... I get this error in my Javascript base code : "Fetch API cannot load file:///C:/Users[...]data.json. URL scheme must be "http" or "https" for CORS request"

All the answers I see online says that a local server is needed to use fetch with a file. But I would need to find solutions without using a local server.

Here is my code :

function getData() {

fetch('data.json')
    .then(res => res.json())
    .then(data => {
        console.log(data)
    })

};

getData();

My files HTML et JS are well linked and my file data.json is located in the same folder.

Somebody (who has understood my problem :) could give me some help/advice please? Thanks

Nico
  • 11
  • 2
  • 1
    Duplicate: https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local – Quentin Jun 01 '21 at 08:00

1 Answers1

0

It is not very wise to make that decision if you can avoid it, but there are different free websites that you could use in the same exact way, for example extendsclass.com has a free json server that you can use to make your own server. All you have to do is make an account and send a fetch request to the api that they give you (with a limit of 10,000 request per month).