Posted By

ebiansyah1402 on 11/15/10


Tagged

jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bmeraly
Mithun


jq Grab random quote with jquery and Tumblr JSON


 / Published in: JavaScript
 

This example grab content from StartupQuote.com. The ultra cool and super inspiring tumblr blog.

  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Tumblr test</title>
  6. </head>
  7. <body>
  8.  
  9. <div id="data">
  10.  
  11. </div>
  12.  
  13. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
  14.  
  15. <script type="text/javascript">
  16. var randomNum = Math.ceil(Math.random()*20);
  17.  
  18. $.getJSON('http://startupquote.com/api/read/json?filter=text&start='+randomNum+'&callback=?',
  19. function(data) {
  20. $.each(data.posts, function(i, posts){
  21. var photocaption = this["photo-caption"];
  22.  
  23. $('<p>' + photocaption + '</p>').appendTo('#data');
  24. if ( i == 0 ) return false;
  25. });
  26. });
  27. </script>
  28.  
  29. </body>
  30. </html>

Report this snippet  

You need to login to post a comment.