SaschaDeWaal
SaschaDeWaal

Reputation: 139

load JSONP with AngularJS

I try to load a JSONP File with AngularJS. This is my code:

var urlCal = 'http://www.google.com/calendar/feeds/[email protected]/public/full';
var allParams = {
    "alt" : "json-in-script",
    "orderby" : "starttime",
    "max-results" : "15",
    "singleevents" : "true",
    "sortorder" : "ascending",
    "futureevents" : "true" 
}
$http.jsonp(urlCal + "?callback=bla", {params: allParams})
.success(function(data){
    console.log(data);
});

but when I run this in the brouwser it sows me this error: "Uncaught ReferenceError: bla is not defined "

I think the problem is that the json file starts with "// API callback" but I am not sure.

Can somebody help me?

Upvotes: 0

Views: 59

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191729

Per Angular's $http.jsonp documentation, you need to use JSON_CALLBACK rather than a named callback:

"?callback=JSON_CALLBACK"

Angular will create the callback function name automatically. Otherwise you would have to define bla.

Upvotes: 2

Related Questions