0

I have searched and searched, but all results I found are for a webpage on a server, not a local file which should be legal to lookup. Whenever I do this:

var music = fetch("playback.json").then(response => response.json());

I get this error:

Fetch API cannot load file:///C:/[removed path]/json_store/playback.json. URL scheme must be "http" or "https" for CORS request.

Folder structure looks like this:

/json_store/
   /index.html
   /script.js
   /playback.json

My HTML/JS file are in the same directory as the JSON file, but it seems this is still giving me an error for some reason. Also according to Mozilla's docs this IS legal to do, as they even provide an example for it. Is there something I am doing wrong, or was this feature removed?

CorruptComputer
  • 328
  • 3
  • 16
  • what does firefox developer console say? does it throw a 404? – mahlatse Sep 24 '18 at 00:28
  • `Fetch API cannot load file:///C:/[removed path]/json_store/playback.json. URL scheme must be "http" or "https" for CORS request.` Is what the console says. – CorruptComputer Sep 24 '18 at 00:31
  • 3
    You can't use AJAX without a webserver, period, fetch or XMLHttpRequest will no work (unless you use specific flags that disable security when launching your browser). You need to host your script on a local webserver – mpm Sep 24 '18 at 00:42

1 Answers1

-2

I would rather serve the file using an HTTP server than fetching the file.

  • I cannot do that, as the file changes constantly. I need to keep fetching it to check for updates. Uploading it to a server would cause it to never be updated unless I do it manually. – CorruptComputer Sep 24 '18 at 00:51