Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the JSONP callback function in AngularJS

I'm trying to fetch data from a web API via Angular $resource service. The service exposes JSONP interface, but does not allow setting the callback name. Everything works well, my requests goes out, the data returns, the script is injected and then it fails because the callback function is not defined.

Angular documentation is very sparse on this, but it seems that the default callback function Angular sets up is: JSON_CALLBACK, and there's no info how to change that so that it matches the function returned by the foreign API.

Thanks.

like image 401
klozovin Avatar asked Jun 23 '26 08:06

klozovin


1 Answers

I don't think that there is any provision to override that callback.

$resource is high level Restful api based on $http service.

You can use $http apis which returns http promise object and letting you write your success callback wherein you can process data returned from ajax request.

e.g. http://docs.angularjs.org/api/ng.$http#jsonp

like image 171
Ashish Avatar answered Jun 25 '26 20:06

Ashish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!