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); ...

Get Mastering jQuery UI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.