Monday, 1 June 2015

Angularjs JSONP

$http.get() and $ and put() and delete() are very commons functions.

However, there is one more function: JSONP, you can get more information from there:$http

get() and post() put and delete are using XMLHttpRequest object, JSONP uses JSONP object.

You can get more information about JSONP from there:

Flickr feed use JSONP :

To call this endpoint, you must specify the format=json.

One more hidden parameter of JSONP is jsoncallback. if you access the endpoint by browser you will see:

You can see it does't return a json blob.  it is a javascript function with a json blob as a parameter.

So, if you call this endpoint with javascript, you need have a function called jsonFlickrFeed.

Angularjs handle this differently:  The name of the callback should be the stringJSON_CALLBACK.

You can do like this:


Put it into url or into params.

Then do callbacks like .get() and .post()

No comments:

Post a comment