Tuesday 26 July 2016

cors - Angular 5 Access-Control-Allow-Origin error with localhost




I'm leaning Angular, trying to use HTTP get to a file on my PC. I want to simulate the server scenario so tried serving the file with the following, (live-server, browser-sync & xampp) one at a time, but with every try I get the error




Failed to load http://localhost/ng-data/products.json: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:4200/' that is not equal to the supplied origin. Origin 'http://localhost:4200' is therefore not allowed access





When I paste the url (http://localhost/ng-data/products.json) in my browser I can get the file.


Answer



Because you're testing, I suggest you use the Chrome extension. Please search this in the Chrome extension list as shown below and then enable it. Probably your problem will be solved.



enter image description here


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...