Skip to content

Instantly share code, notes, and snippets.

@igustafson
Last active August 30, 2019 03:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igustafson/675e4b581ea713c78f4d to your computer and use it in GitHub Desktop.
Save igustafson/675e4b581ea713c78f4d to your computer and use it in GitHub Desktop.
Reddit API AJAX Request Example Using jQuery
var searchTerm = 'cats';
$.ajax(
"https://www.reddit.com/subreddits/search.json",
{
data: { q: searchTerm },
success: function(responseData) {
if (responseData.data.children.length > 0) {
console.log('# of results: ' + responseData.data.children.length);
$.each(responseData.data.children, function(idx, searchResult) {
console.log("--- Title of Subreddit: " + searchResult.data.title);
});
} else {
console.log("No subreddits match the search query!");
}
},
error: function() {
alert("Something didn't work!");
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment