AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https
This error is happening because you are just opening html documents directly from the browser. To fix this you will need to serve your code from a webserver and access it on localhost. If you have Apache setup, use it to serve your files. Some IDE's have built in web servers, like JetBrains IDE's, Eclipse...
If you have Node.Js setup then you can use http-server. Just run npm install http-server -g
and you will be able to use it in terminal like http-server C:\location\to\app
.
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Your URL is missing the scheme (http:
). You are trying to use a relative URL, which is resolving to something like file:///blah/blah/blah/localhost:3000
… and as the error message says, you can't load data from file:
URLs as CORS isn't supported there. Use the right URL.
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.
requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https
I think you must specify file:///
in the function call
<button type = "button" (click) = "makeRequest('file:///E:/xampp/Angular-cli/Login/src/app/employees.txt')">File Test</button>
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.
Related Topics
"Uncaught Typeerror: Illegal Invocation" in Chrome
Submit Multiple Forms With One Submit Button
JavaScript - Append HTML to Container Element Without Innerhtml
Animate Element to Auto Height With Jquery
How to Make HTML Element Resizable Using Pure JavaScript
How to Parse an Rss Feed Using JavaScript
Performance of Mutationobserver to Detect Nodes in Entire Dom
How to Calculate the Xpath Position of an Element Using JavaScript
Including Both Href and Onclick to HTML ≪A≫ Tag
Stop/Close Webcam Stream Which Is Opened by Navigator.Mediadevices.Getusermedia
How to Clear the Contents of an Iframe from Another Iframe
Selecting All Text in HTML Text Input When Clicked
How to Set Value of Input Text Using Jquery
How to Add/Remove Several Classes in One Single Instruction With Classlist
Stopping Gif Animation Programmatically
Get the Position of a Div/Span Tag
Js Function Named 'Animate' Doesn't Work in Chrome, But Works in Ie