sandbox.js:1 Fetch API cannot load file:///C:/Users/Lizzi/Desktop/novice%20to%20ninja/todos/luigi.json. URL scheme must be "http" or "https" for CORS request

I"m new to aynchronouse programming but I have read up on CORS solutions and tried things like getting a chrome extension and disabling web security for my google chrome but it still doesn"t work.

fetch("todos/luigi.json").then((response)=>{ console.log("resolved",response);}).catch((err)=>{ console.log("rejected", err);});


You are watching: Url scheme must be "http" or "https" for cors request.

javascript promise fetch
Share
Improve this question
Follow
edited Sep 27 "19 at 5:37

*

Gayan S. Muthukumarana
1,20611 gold badge88 silver badges2525 bronze badges
asked Sep 27 "19 at 5:16
*

Elizabeth EssienElizabeth Essien
19311 gold badge11 silver badge66 bronze badges
6
| Show 1
more comment

1 Answer 1


Active Oldest Votes
24
You need to be serving your index.html locally or have your site hosted on a live server somewhere for the Fetch API to work properly. The files need to be served using the http or https protocols.

If you just clicked on your index.html from your file explorer than your browser is grabbing those files directly from your file system. This is why the error is showing you an absolute path from the root folder on you computer.

Try installing one of these...- npm serve- Live server (an extension for Visual Studio Code if you are using that)

Or whatever server that will work with your environment.

Should work fine once you spin up a server :) happy coding!


Share
Improve this answer
Follow
answered Sep 27 "19 at 6:36
*

Nick SugarNick Sugar
33922 silver badges55 bronze badges
5
Add a comment |

Not the answer you're looking for? Browse other questions tagged javascript promise fetch or ask your own question.


The Overflow Blog
Featured on Meta
Linked
1884
Disable same origin policy in Chrome
14
Chrome - Fetch API cannot load file. How to workaround?
Related
852
How can you check for a #hash in a URL using JavaScript?
584
“Origin null is not allowed by Access-Control-Allow-Origin” error for request made by application running from a file:// URL
342
How to save up another precious HTTP-request for the tiny favicon?
409
How can I get the status code from an HTTP error in Axios?
13
Fetch API cannot load file:///C:/Users/Jack/Desktop/Books_H/book-site/public/api/books. URL scheme must be "http" or "https" for CORS request
Hot Network Questions more hot questions
*

lang-js
Stack Overflow
Products
Company
Stack Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.11.24.40828




See more: Mellon Collie And The Infinite Sadness Wallpaper, 43 Mellon Collie And The Infinite Sadness Ideas

Stack Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.