Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am getting this error. XMLHttpRequest cannot load http://communityempowerment.org.pk/test-sample/api/get_category_index/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

my code is

.controller('MenuCtrl', function($http, $scope){

    $scope.categories = [];

    $http.get("http://communityempowerment.org.pk/test-sample/api/get_category_index/").then
        (function(data){
            $scope.categories = data.data;
            console.log(data);
        }, function(err){
            console.log(err);
    })

})
share|improve this question
    
You can't do ajax requests to random cross-origin resources, it violates the same-origin policy. The only workaround is to control the server and add the correct headers, return JSONP, or use your own server to make the request. – adeneo Mar 5 at 5:28

The server that is serving http://communityempowerment.org.pk/test-sample/api/get_category_index/ doesn't allow cross-origin requests. Take a look at CORS on MDN. If you control the server, you can change the header Access-Control-Allow-Origin to either a specific set of domains, or a wildcard * to allow access from all origins.

share|improve this answer

Your code is correct the problem is coming from the server.You should enable cross-origin. http://enable-cors.org/server.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.