1

I'm trying to consume a josn api (I'm very new to angularjs) and I'm getting the following error when trying to consume a json api using $http.get

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.

  • angularjs version: 1.3.8
  • browser: chrome/firefox/safari
  • enable CORS on the server side is not an option
  • already tried jsonp without success
  • the url works when I use the browser (I see the json response)

My Code:

angular.module('MyApp', [])
.config(function ($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
})

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

var url = "https://myurl";

$http.get(url)
.success(function(data){
    console.log(data);
});

});

Thanks in advance!

gs-rp
  • 377
  • 1
  • 3
  • 16

0 Answers0