Created
April 28, 2011 22:32
-
-
Save sente/947491 to your computer and use it in GitHub Desktop.
An example of a retrieving data from reddit's JSON(p) api using jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
Stuart Powers | |
http://sente.cc/ | |
http://twitter.com/stuartpowers | |
--> | |
<html> | |
<head> | |
<script src="http://j.mp/jqymin"></script> | |
</head> | |
<body> | |
<div id="reddit-content"> | |
</div> | |
<script> | |
$.getJSON( | |
"http://www.reddit.com/r/pics.json?jsonp=?", | |
function foo(data) | |
{ | |
$.each( | |
data.data.children.slice(0, 10), | |
function (i, post) { | |
$("#reddit-content").append( '<br>' + post.data.title ); | |
$("#reddit-content").append( '<br>' + post.data.url ); | |
$("#reddit-content").append( '<br>' + post.data.permalink ); | |
$("#reddit-content").append( '<br>' + post.data.ups ); | |
$("#reddit-content").append( '<br>' + post.data.downs ); | |
$("#reddit-content").append( '<hr>' ); | |
} | |
) | |
} | |
) | |
.success(function() { alert("second success"); }) | |
.error(function() { alert("error"); }) | |
.complete(function() { alert("complete"); }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!! have been looking for this for a while