Error: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

If you are facing this error it’s because your page is trying to load a local file using file:// or C:/ (you can see it in the URL on your browser). It happened to me one time, that’s because I created a HTML page and simply double-clicked on it to open it on the browser, my page was using a JSON file from the same folder, and when I checked the console this error was there:

Failed to load file:///C:/project/myProject/data.json: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Turned out I needed a webserver for this. The solution was to install one on my computer (WampServer or Lamp will do fine) and host my page on it, this fixed the problem for me.

Recommended for you

Angular2: How to Sort a JSON Dataset by Field To be able to sort an array we don't need anything specific from angular2, it can be accomplished just by using regular javascript, more specifically, we have to use the function sort() from the Array object, let's see an example: someArray.sort(function(a, b){ if ( a.someField < b.someFi...
How to load a JSON file in Reactjs It's really easy to load data from a JSON file in React. In this post I'm going to show you how you can do that. First, of course, we need a JSON file, you probably already have yours, but I'm using this movies list for this example: data.json Now we have to place this file somewhere ins...
Using jQuery with Angular2 I know the idea of using jQuery with Angular2 may seen a little bit weird for lots of you, as we all know, Angular2 is responsible for managing everything related to our view components and DOM elements, it doesn't sound like a good idea to use another framework to do a job Angular can easily do. ...
Node Express Error: Cannot find module ‘serve-favicon’ This error means you don't have the module 'serve-favicon' installed on your project, here is the full error: Error: Cannot find module 'serve-favicon' at Function.Module._resolveFilename (module.js:542:15) at Function.Module._load (module.js:472:25) at Module.require (module.js:...

Leave a Reply

Your email address will not be published. Required fields are marked *

Obs: Use the tag <pre lang="LANGUAGE"> to include code blocks to your comment.
Example: <pre lang="javascript"> console.log('Test'); </pre>