Problem with consuming JSON


I have looked for different ways to consume my webservice but I have not succeeded. Try this:

.controller('PerfilCtrl',function($scope,$http) {
$http({method: 'POST', url:       ''}).success(function(data)
  $scope.posts = data; // response data 

But I get the following error:

"XMLHttpRequest can not load No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is THEREFORE not allowed access. "

Try to add the header but still does not work.


It looks that your server is nor properly configured to accept CORS requests. You need to allow CORS on your server in order to accept ajax requests from different domains.

Here’s a sample config file for enabling CORS on nginx: