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

How to Load a JSON file in Javascript In this post I'm going to give you a very simple example of how to read a JSON file and display the data on the page. I'll be using jQuery in this example, so if you don't have it on your project don't forget to add the script. So let's get started, first we need a JSON, you probably already have...
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. ...
@angular/cli error when creating project: Unexpected token = After installing @angular/cli lots of people get this error when trying to create the fist angular project: SyntaxError: Unexpected token = at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Modu...
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...

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>