How To Get The Last Tweet Using jQuery

Lots of websites have started using plugins that display the latest tweets from Twitter. Well, here’s a simple jQuery script shared by ayalcinkaya from Mkyong that uses jQuery which basically has the same concept except that it retrieves only the user’s one latest tweet.

jQuery AJAX

$('#last-tweet').click(function(){
 $("#tweet_result").text("Loading......");
 var username = $('#username').val();
 $.ajax({
 type: "GET",
 dataType: "json",
 url: "http://search.twitter.com/search.json?q=from:"+username+"&rpp=1&callback=?",
 success: function(data){
 $("#tweet_result").text(data.results[0].text);
 }
 });
});

An HTML example

<html>
<head>
<title>How to Get Last Tweet with Jquery Example</title>
<script
 src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
 type="text/javascript"></script>
</head>
<body>
 <h1>Get Last Tweet with jQuery</h1>
 username :
 <input type='text' id='username' size='50' value='mkyong' />
 <br />
 <br />
 <h4>
 Last Tweet : <span id="tweet_result"></span>
 </h4>
 <button id="last-tweet">Get Last Tweet (.Ajax)</button>
 <script type="text/javascript">
 $('#last-tweet').click(
 function() {
 $("#tweet_result").text("Loading......");
 var username = $('#username').val();
 $.ajax({
 type : "GET",
 dataType : "json",
 url : "http://search.twitter.com/search.json?q=from:"
 + username + "&rpp=1&callback=?",
 success : function(data) {
 $("#tweet_result").text(data.results[0].text);
 }
 });
 });
 </script>
</body>
</html>     

If you’d like to see the code in action, you can try it out here.

Incoming search terms for the article:

Related Posts

How To Create A Triangular Pixelation Effect Using Photoshop

How to Create Subtle Caption Hover Effects

How To Create A Webpage With A Clean Style Portfolio Layout

How to Create a Sparkling Diamond and Gold Text Effect