Skip to content

Instantly share code, notes, and snippets.

@dongcai
Created August 1, 2018 18:32
Show Gist options
  • Save dongcai/158d9b7ce68cf89def67b4c2a499b707 to your computer and use it in GitHub Desktop.
Save dongcai/158d9b7ce68cf89def67b4c2a499b707 to your computer and use it in GitHub Desktop.
Every request only updates what it needs to be updated
function getRedditFeed() {
var topic = $('#select-topic').val();
$.getJSON("https://www.reddit.com/r/" + topic + ".json", function(data) {
$.each(data.data.children, function(i, item) {
$('<li><a href="' + item.data.url + '" target="_blank">' + item.data.title + '</a></li>').appendTo("#posts");
});
});
}
$(document).ready(function() {
getRedditFeed();
$('#select-topic').change(function() {
$('#posts').html(''); // clear posts
getRedditFeed();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment