Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In response to the OP, there are two problems with your code: you need to set jsonp='callback', and adding in a callback function in a variable like you did does not seem to work.</p> <p>Update: when I wrote this the Twitter API was just open, but they changed it and it now requires authentication. I changed the second example to a working (2014Q1) example, but now using github.</p> <p>This does not work any more - as an exercise, see if you can replace it with the Github API: </p> <pre><code>$('document').ready(function() { var pm_url = 'http://twitter.com/status'; pm_url += '/user_timeline/stephenfry.json'; pm_url += '?count=10&amp;callback=photos'; $.ajax({ url: pm_url, dataType: 'jsonp', jsonpCallback: 'photos', jsonp: 'callback', }); }); function photos (data) { alert(data); console.log(data); }; </code></pre> <p>although alert()ing an array like that does not really work well... The "Net" tab in Firebug will show you the JSON properly. Another handy trick is doing </p> <pre><code>alert(JSON.stringify(data)); </code></pre> <p>You can also use the <strong>jQuery.getJSON</strong> method. Here's a complete html example that gets a list of "gists" from github. This way it creates a randomly named callback function for you, that's the final "callback=?" in the url.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;JQuery (cross-domain) JSONP Twitter example&lt;/title&gt; &lt;script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $.getJSON('https://api.github.com/gists?callback=?', function(response){ $.each(response.data, function(i, gist){ $('#gists').append('&lt;li&gt;' + gist.user.login + " (&lt;a href='" + gist.html_url + "'&gt;" + (gist.description == "" ? "undescribed" : gist.description) + '&lt;/a&gt;)&lt;/li&gt;'); }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;ul id="gists"&gt;&lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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