views:

82

answers:

3
$(function(){
            $.ajax({
                url:'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&callback=?',
                //dataType:'json',
                success:function(data){$('body').append('the data is' +data);}
            });
            });

the above code with dataType line prints out [objects] while with the dataType line commented it prints out nothing ...how can i get it to print the json output from the server rather then the javascript object?

+1  A: 

Try

success:function(data){$('body').append('the data is' +data.urKeyname);}
Pandiya Chendur
+1  A: 

hope you are using firebug,

add this to your code:

success:function(data){console.log(data);}

check the firebug console to see what data object has. Acccordingly use the object like

success:function(data){$('body').append('the data is' +data.key);}

Or use this short hand for getting json encoded data

$.getJSON('ajax/test.json', function(data) {
  $('.result').html('<p>' + data.foo + '</p>'
    + '<p>' + data.baz[1] + '</p>');
});

more info at getJSONdocumentation

Ashish Rajan
You would need to append `?jsoncallback=?` to your `getJSON` example, since this is a cross-domain situation there are other factors at play.
Nick Craver
+1  A: 

First, you may want to check out Twitter's API docs, it has all this broken down with descriptions, here's the direct link to user_timeline.

Alternatively, here's the manual route :) To inspect it you have a few options, if you're using Firefox/Firebug or Chrome, you can log it to the console, like this:

$.ajax({
  url:'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&amp;callback=?',
  dataType:'json',
  success:function(data){ console.log(data); }
});

Another option is just visiting the URL: http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&amp;callback= Then take the result and pop it in something like JSONLint to format it for easier browsing.

What you'll probably end up wanting is something like this:

data[0].user.friends_count
Nick Craver