Santi
Santi

Reputation: 501

Error reading JSONP in AngularJS

I am trying to run with success the example in http://jsfiddle.net/srlopez/zXPSB/4/

function MyController($scope, $http) {
$http({
    method: 'JSONP',
    url: 'https://212.142.196.44/cardiopen/episodio/list/2'
}).
success(function (data, status) {
    console.log('data:', data);
}).
error(function (data, status) {
    console.log('status:', status);
    console.log('data:', data);
});

}

It reads a JSON from that url but always get error

Uncaught SyntaxError: Unexpected token : 212.142.196.44/cardiopen/episodio/list/2 status: 0 data: undefined

And the url is ok. Can any one help me

Upvotes: 0

Views: 152

Answers (1)

Omar Meky
Omar Meky

Reputation: 606

Just use the shorthand method:

$http.jsonp('https://212.142.196.44/cardiopen/episodio/list/2').then(function(response){
    console.log(response.data);
});

Upvotes: 1

Related Questions