Skip to content Skip to sidebar Skip to footer

Xmlhttprequest Issue: Cross Origin Requests Are Only Supported For Protocol Schemes: Http, Data, Chrome, Chrome-extension, Https

Trying to get some data from a local JSON file stored in the same directory, I get this: Access to XMLHttpRequest at 'file:///C:/Visual%20Studio%20Code/Practice/customer.json' f

Solution 1:

Some browsers prohibit any kind of ajax from local files (resources loaded via the file: scheme). You appear to be using one of them.

The solution is to install a local webserver and load the resources via http: instead. Some IDEs have a minimal webserver included, either directly or via an extension. But if not, a local install of Apache or nginx is fairly easy to install, or you can roll your own with Express.js or Koa.js or similar.

This isn't the only subtle difference between how browsers handle file: resources vs. http:/https: resources, so when doing web development, it's always best to use a local web server, not file:.

Post a Comment for "Xmlhttprequest Issue: Cross Origin Requests Are Only Supported For Protocol Schemes: Http, Data, Chrome, Chrome-extension, Https"