Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm facing this issue with chrome and IE. I have developed HTML player in that i used XML to load the data inside that player. all pages have been accessed through XML.it work fine when I use any server to load that data inside player.I use WAMP server now. But now I'm thinking about making it as an offline version and write it inside CD. but when I open my player.html file directly without having server, the XML data not going to load.it showing following error in the console.

XMLHttpRequest cannot load file:///C:/wamp/www/TTT_BR/english.xml. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

like image 716
Amit Golhar Avatar asked May 12 '17 11:05

Amit Golhar


People also ask

How do I fix cross origin requests are only supported for protocol schemes?

So you can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to: http://example.com/path/to/model. So even though your file originates from the same host (localhost), but as long as the scheme is different (http / file), they are treated as different origin.

Does CORS require https?

CORS requests may only use the HTTP or HTTPS URL scheme, but the URL specified by the request is of a different type. This often occurs if the URL specifies a local file, using the file:/// scheme.

How do I enable CORS in Chrome?

Please note that, when the add-on is added to your browser, it is inactive by default (toolbar icon is grey C letter). If you want to activate the add-on, please open the toolbar popup and press the toggle button on the left side. The icon will turn to an orange C letter.

Why are cross origin requests blocked?

If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at $somesite" indicating that the request was blocked due to violating the CORS security rules.


3 Answers

you must run your app in the server , use node js

1- Install NodeJS // Hint: If you're on a Mac, you want to install and use Homebrew for this

2- Open your favorite terminal emulator

2- Install http-server by running: npm install http-server -g

3- Start http-server by running: http-server 'path/to/your/angular/root/directory' -o

That last command — specifically, the -o flag — should open a browser window at: localhost:8080

OR// use cd to find your directory app
and use this command : http-server . -o

"." mean your current directory

you can see : https://teamtreehouse.com/community/i-am-not-able-to-load-my-json-file

like image 109
Hussein Saad Avatar answered Oct 26 '22 23:10

Hussein Saad


for testing/development purposes, the simplest solution is to use firefox browser.

like image 40
meol Avatar answered Oct 26 '22 23:10

meol


Pretty much everyone has python on mac/linux by default. Who doesent, can easily get it.

python -m SimpleHTTPServer will give you a local server @ http://localhost:8000. From there you can access whatever file you'd like for your app.

Note: use python -m http.server for python versions 3.0+

like image 35
Nick Drozd Avatar answered Oct 27 '22 01:10

Nick Drozd