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.


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.

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

链接地址: http://www.djcxy.com/p/47556.html

上一篇: 有自定义回调的Angular Service JSONP请求

下一篇: 在AngularJS中设置JSONP回调函数