Created
June 24, 2013 15:53
-
-
Save applesaucesome/5851100 to your computer and use it in GitHub Desktop.
reddit ajax
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 PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>Reddit</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
/* | |
http://www.reddit.com/dev/api | |
http://www.reddit.com/api/info.json?jsonp=foo&url=http://www.reddit.com/r/gaming | |
http://www.reddit.com/.json?limit=1&jsonp=alert | |
*/ | |
var jsonurl,reddit,redditLength,redditArticle; | |
jsonurl = 'http://www.reddit.com/.json?limit=10&jsonp=redditFeed'; | |
function redditFeed(feed){ | |
reddit = feed.data.children; | |
redditLength = feed.data.children.length; | |
for(var i=0; i<redditLength; i++){ | |
articleAuth = reddit[i].data.author; | |
articleUps = reddit[i].data.ups; | |
articleDowns = reddit[i].data.downs; | |
articleTitle = reddit[i].data.title; | |
articleUrl = reddit[i].data.url; | |
articleComp = | |
'Title: ' + articleTitle + ' ' | |
+ 'Author: ' + articleAuth + ' ' | |
+ 'Url: ' + articleUrl + ' ' | |
+ 'Upboats: ' + articleUps + ' ' | |
+ 'Downboats: ' + articleDowns; | |
/* | |
redditArticle = document.createElement('img'); | |
redditArticle.title = imgTitle; | |
redditArticle.src = 'http://farm'+farmId+'.staticflickr.com/'+serverId+'/'+photoId+'_'+secretId+'_m.jpg'; | |
redditArticle.body.appendChild(flickImg); | |
*/ | |
redditArticle = document.createTextNode(articleComp); | |
document.body.appendChild(redditArticle); | |
document.body.appendChild(document.createElement('br')); | |
document.body.appendChild(document.createElement('br')); | |
} | |
} | |
$(document).ready(function(){ | |
$.ajax({ | |
url: jsonurl, | |
dataType: 'jsonp', | |
success: function (feed){ | |
redditFeed(feed); | |
console.log('Yes!'); | |
}, | |
error: function() { | |
console.log('Uh Oh!'); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="myDiv"> </div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment