I am trying to invoke a REST web service from my new Angular app. When a request is made I am getting this error:
XMLHttpRequest cannot load http://localhost:8080/WebService. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
I found out this is happening because the browser is not allowing such action.
In StackOverflow one of the solutions was to disable a few security options. I tried doing this and it didn't work, I was getting the same error.
Then another solution suggested moving the project to a server. So I moved my project to my www
folder in WAMP. It didn't work because I needed to activate the headers_module
and then modify httpd.conf
adding this:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</IfModule>
So I activated the module and modified the general config file (can't remember how to do it just form my web project) and restarted WAMP. It still won't work.
The only think I could do to make it work was creating a web project in Eclipse JEE and run it on a Tomcat server. But I don't really want to do this.
How can I fix this problem?
Edit I also tried adding this to my angular app:
app.config([ '$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
The issue remained.