Angularjs Error: Cross Origin Requests Are Only Supported For Protocol Schemes: Http, Data, Chrome-Extension, Https

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



Leave a reply



Submit