Newbee
Newbee

Reputation: 25

AngularJS RESTAPI call throwing error

I'm learning AngularJS. I was trying to make a RESTapi call using standard $http service but I'm not getting a successful response. Any clue what I'm doing wrong here?

I'm calling the URL (URL is rendering fine when I ping it): http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json

The error i'm receiving is:

{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote","params":{"format":"json"},"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}

My Angularjs test code is:

angular.element(document).ready(function(){
angular.bootstrap(document.getElementById('app2'),['app2']);
});

angular.module('app2',[])
  .controller('testNamesCtrl',function($scope,$http){

        $http({method:'GET',url:'http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote',params:{format:"json"}})
        .then(
                function(response){
                    $scope.record = response.data;
                $scope.record1 = response;
            }, function(response){
                $scope.record1 = response;
            });
  });

Upvotes: 2

Views: 433

Answers (1)

user3335966
user3335966

Reputation: 2745

As I understand, You try make cross domain request. You can try use $http.jsonp(url) for this. But it was work only if server allows use JSONP.

And as I see, this server not allowed. In this case, you can prepare data on Your server.

echo file_get_contents(url);

Example;

Upvotes: 1

Related Questions