Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE: since Angular 1.6</strong> </p> <blockquote> <p>You can no longer use the JSON_CALLBACK string as a placeholder for specifying where the callback parameter value should go</p> </blockquote> <p>You must now define the callback like so:</p> <p><code>$http.jsonp('some/trusted/url', {jsonpCallbackParam: 'callback'})</code></p> <p>Change/access/declare param via <code>$http.defaults.jsonpCallbackParam</code>, defaults to <code>callback</code></p> <p>Note: You must also make sure your URL is added to the trusted/whitelist:</p> <p><code>$sceDelegateProvider.resourceUrlWhitelist</code> </p> <p>or explicitly trusted via: </p> <p><code>$sce.trustAsResourceUrl(url)</code></p> <p><strong><code>success/error</code> were <a href="https://code.angularjs.org/1.5.10/docs/api/ng/service/$http#deprecation-notice" rel="noreferrer">deprecated</a></strong>.</p> <blockquote> <p>The <code>$http</code> legacy promise methods <code>success</code> and <code>error</code> have been deprecated and will be removed in v1.6.0. Use the standard then method instead. If <code>$httpProvider.useLegacyPromiseExtensions</code> is set to <code>false</code> then these methods will throw <code>$http/legacy error</code>.</p> </blockquote> <p>USE:</p> <pre><code>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); }); </code></pre> <p><strong>Previous Answer: Angular 1.5.x and before</strong></p> <p>All you should have to do is change <code>callback=jsonp_callback</code> to <code>callback=JSON_CALLBACK</code> like so:</p> <pre><code>var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK"; </code></pre> <p>And then your <code>.success</code> function should fire like you have it if the return was successful.</p> <p>Doing it this way keeps you from having to dirty up the global space. This is documented in the AngularJS documentation <a href="https://docs.angularjs.org/api/ng/service/$http#jsonp" rel="noreferrer">here</a>.</p> <p>Updated Matt Ball's fiddle to use this method: <a href="http://jsfiddle.net/subhaze/a4Rc2/114/" rel="noreferrer">http://jsfiddle.net/subhaze/a4Rc2/114/</a></p> <p><strong>Full example:</strong></p> <pre><code>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); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload