Skip to content

Instantly share code, notes, and snippets.

@ahmad24
Created December 8, 2013 07:09
Show Gist options
  • Save ahmad24/7854178 to your computer and use it in GitHub Desktop.
Save ahmad24/7854178 to your computer and use it in GitHub Desktop.
jQuery : load tweets ajax
<script type="text/javascript">
// When the DOM is ready, add behavior to the link
$(document).ready(function(){
$('#load').click(function(){
load_tweets();
// Skip default behavior (ie redirecting to the link href)
return false;
});
});
// Main function: load tweets in JSON
function load_tweets() {
// Activity indicator:
$('#tweets').html('loading tweets...');
// Ajax JSON request
$.getJSON(
// Use a JSONP (with callback) URL
'http://twitter.com/status/user_timeline/ozh.json?count=5 & callback=?',
// Function that will handle the JSON response
function(data) {
// Put empty <ul> in the placeholder
$('#tweets').html('<ul></ul>');
// Read each object in the JSON response
$(data).each(function(i, tweet) {
$('#tweets ul').append('<li>'+tweet.text+'</li>');
});
}
);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment