Take the 2-minute tour ×

I'm having a lot of trouble getting any results out of the JSONP datatype of the jQuery $.ajax() function. This is my jQuery code:

      type: 'get',
      url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jquery',
      dataType: 'jsonp',
      succes: function(data) {
        $.each(data, function() {
            .append('<img src="'+ this.profile_image_url +'"/>')
            .append('<p>'+ this.text +'</p>')
      error: function() {
        alert('Iets gaat fout!!');

I've assigned the #show_tweets ID to a P tag. #tweets_gallery is an empty DIV. Now, I know I could also use the $.getJSON() function, but I just want to know how I can properly retrieve JSONP results with a $.ajax() request. I've clicked several times and it doesn't output anything.

Thanks in advance!

share|improve this question
check this website :) it will help remysharp.com/2007/10/08/what-is-jsonp –  shereifhawary Dec 22 '10 at 11:35
jsonp: 'jsonp_callback', instead of dataType: 'jsonp', –  shereifhawary Dec 22 '10 at 11:36
add comment

1 Answer

In case it's an error because of your typo:

succes: function(data) should be success: function(data)

In reply to your comment below, the reason profile_image_url is undefined is because there is no property in the root scope. The JSON returned from twitter is in the form of:

  "text" : "The twitter text",
  "user" : {
           "profile_image_url" : "http://path.to.profileimage/",

So this.text exists (which is why you get the value) but you should be accessing the profile image as this.user.profile_image_url

See the twitter API for how the JSON is structured.

share|improve this answer
LOL, that was exactly the problem! You have a keen eye, sir! Okay, I have one last question though: my AJAX request doesn't return anything useful when I define "this.profile_image_url". "this.text" works perfectly though. "this.profile_image_url" however, remains literally undefined. I'm expecting to see the jQuery avatar popping up in this case. Have I got the wrong scope for this? –  Martijn1981 Dec 22 '10 at 11:44
@Martijn1981 It's because the profile image is under the user object in the data that your reading. I've updated my answer in response to your comment. –  Jonathon Bolster Dec 22 '10 at 12:30
Thanks Jonathan! –  Martijn1981 Dec 24 '10 at 9:10
add comment

Your Answer


