Book Image

Mastering jQuery UI

By : Vijay Joshi
Book Image

Mastering jQuery UI

By: Vijay Joshi

Overview of this book

Table of Contents (19 chapters)
Mastering jQuery UI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying posts from the reddit front page


We already created an example using the reddit API in Chapter 4, Creating a Tabbed News Reader. If you have gone through it, you can directly skip the theory section and directly use the code and implement it.

Unlike Chapter 4, Creating a Tabbed News Reader, in this widget we will display the posts from the reddit front page. Like earlier widgets, we will call the reddit API for JSON of front page posts. Once data is received, we will iterate in response items and create the DOM. Write the following code inside initReddit method to call the API:

var apiURL = 'http://www.reddit.com/r/all.json';
$.ajax(
{
  url: apiURL,
  dataType: "jsonp",
  jsonp: 'jsonp',
  success: function(data)
  {
  var x = {a : data};
  console.log(x);
  $('#reddit').html(dashboard.getRedditThreadList(data.data.children));
  },
  error: function (a,b,c)
  {
  alert('Error getting data');
  }
});

You can get the JSON for any subreddit by adding .json at the end of its name. Since...