jq Grab random quote with jquery and Tumblr JSON


/ Published in: JavaScript
Save to your folder(s)

This example grab content from <a href="http://startupquote.com/">StartupQuote.com</a>. The ultra cool and super inspiring tumblr blog.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.