Hi All,

I got stuck at one point while calling REST service from my Angular JS code 
:

*Service:*

app.factory('UserFactory', function ($resource) {
    return $resource('http://localhost:8080/demoApp/service/users', {}, {
        show: { method: 'GET', isArray: true },       
    })
});

*Controller:*
function userListController($scope, UserFactory){   
    $scope.showUser = function () {
        alert("Show user ...");
        $scope.fetchedData = [];
        $scope.users = UserFactory.show();
        $scope.fetchedData.push($scope.users);
        
    };    
}

In order to overcome the CORS we have implemented Java CORS Filter as below 
-

        @Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
System.out.println("----------- INSIDE FILTER ------------");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, 
DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
 chain.doFilter(req, res);
 }

It is working perfect with $http.jsonp.  But while we are calling with 
above way we got following error in Javascript console of the browser 
(Chrome) :

XMLHttpRequest cannot load http://localhost:8080/demoApp/service/users 
<http://localhost:8080/InternetBanking_v1/service/users>. No 
'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:63342 <http://localhost/>' is therefore not 
allowed access.

Please help me ...

Regards,

Jayanta P.


-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to