Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https
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
Cross origin requests are only supported for HTTP. error when loading a local file
My crystal ball says that you are loading the model using either file://
or C:/
, which stays true to the error message as they are not http://
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
Origin is defined in RFC-6454 as
...they have the same
scheme, host, and port. (See Section 4 for full details.)
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.
CORS Error: “requests are only supported for protocol schemes: http…” etc
XMLHttpRequest cannot load localhost:4201/ticker. Cross origin
requests are only supported for protocol schemes: http, data, chrome,
chrome-extension, https.
Any time you see that “only supported for protocol schemes” message, it almost certainly means you’ve just forgotten to put the https
or http
on the request URL in your code.
So in this case, the fix is to use the URL http://localhost:4201/ticker
in your code here:
this._baseUrl = 'http://localhost:4201/';
…because without the http://
there, localhost:4201/ticker
isn’t really the URL you intend.
Related Topics
Insert External Page HTML into a Page HTML
How to Position a Div in a Specific Coordinates
Jquery Validation Using the Class Instead of the Name Value
Multiple Select Limit Number of Selection
Javascript/HTML Storage Options Under File Protocol (File://)
Jquery - Redirect with Post Data
Force Page Zoom at 100% with Js
What the Difference of This.State and This.Setstate in Reactjs
Decode HTML Entities in JavaScript
How to Make a Button Redirect My Page to Another Page
Change How Fast "Title" Attribute's Tooltip Appears
Jquery Change Event on an <Input> Element - Any Way to Retain Previous Value
How to Retrieve If the Popstate Event Comes from Back or Forward Actions with the HTML5 Pushstate
Syntax for an Async Arrow Function