Skip to content

Instantly share code, notes, and snippets.

@skippednote
Created August 18, 2013 11:36
Show Gist options
  • Save skippednote/6261226 to your computer and use it in GitHub Desktop.
Save skippednote/6261226 to your computer and use it in GitHub Desktop.
Ajax request to sub-reddit
$.ajax({
url: 'http://www.reddit.com/r/aww/.json?jsonp',
dataType: 'jsonp',
success: function( resp ) { resp.data.children.forEach(function(entry, i){
var pic = "<img src="+ entry.data.url+">";
console.log(i);
$("#target").append("<li>" + pic + "</li>");
i++;
});
},
error: function( req, status, err ) {
console.log( 'something went wrong', status, err );
},
jsonp : 'jsonp'
});
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="app.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div id="target">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment