Setting up JSONP callback function in AngularJS

I am trying to fetch data from a web API via the Angular $ resource service. The service exposes the JSONP interface, but does not allow you to set the callback name. Everything works well, my requests disappear, data is returned, a script is injected and then it fails because the callback function is not defined.

Angular documentation is very sparse, but it seems that the default Angular callback function sets:, JSON_CALLBACK

and there is no information on how to change this to match the function returned by foreign APIs.

Thank.

+3


source to share


1 answer


I don't think there is any condition to cancel this callback.

$ resource is high level. A recovery api based on the $ http service.



You can use $ http apis which returns a promise object and allows you to write a success callback where you can handle the data returned from the ajax request.

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

+1


source







All Articles