UPDATE: as of Angular 1.6
The use of the JSON_CALLBACK string as a placeholder for specifying where the callback parameter value should go is no longer valid
Now, you need to define the callback like this:
$http.jsonp('some/trusted/url', {jsonpCallbackParam: 'callback'})
Modify/access/declare parameters using
$http.defaults.jsonpCallbackParam
, which defaults to
callback
Remember: Ensure that your URL is added to the trusted/whitelist:
$sceDelegateProvider.resourceUrlWhitelist
or explicitly trust it with:
$sce.trustAsResourceUrl(url)
success/error
have been deprecated.
The legacy promise methods success
and error
of $http
have been deprecated and will be removed in v1.6.0. Instead, use the standard then method. If
$httpProvider.useLegacyPromiseExtensions
is set to false
, these methods will throw an error.
USAGE:
var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts"
var trustedUrl = $sce.trustAsResourceUrl(url);
$http.jsonp(trustedUrl, {jsonpCallbackParam: 'callback'})
.then(function(data){
console.log(data.found);
});
Previous Answer: Angular 1.5.x and earlier
To make the change from callback=jsonp_callback
to callback=JSON_CALLBACK
, simply do this:
var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";
If the return is successful, your .success
function should work as intended without polluting the global space. This method is documented in the AngularJS documentation here.
Updated version of Matt Ball's fiddle using this technique: http://jsfiddle.net/subhaze/a4Rc2/114/
Complete example:
var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(function(data){
console.log(data.found);
});