开发者

getJson + Twitter

Im not that much into programation but I've been trying to edit a base code one 开发者_如何学Gowith another ones to display more than 1 tweet but it dosen't work, could anyone help me?

 $.getJSON("http://twitter.com/status/user_timeline/user.json?count=3&callback=?", 
  function(data) {
      $("#tweet").html(data[0].text);
  }); 

Thanks!


data is an array. So data[0] accesses the first tweet returned from twitter. You need to iterate over the array and append the other tweets to your div.

$.getJSON("http://twitter.com/status/user_timeline/user.json?count=3&callback=?", 
function(data) {
  $(data).each(function() {
     $("#twitter").append($(document.createElement('div'))
        .html(this.text).addClass('tweet'));
  }
}); 

Edit: Changed selector to target #twitter div and add a tweet class to each tweet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜