Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kylecoberly
Last active May 28, 2017 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylecoberly/7035f18c4a7fbf008a01658a63190e93 to your computer and use it in GitHub Desktop.
Save kylecoberly/7035f18c4a7fbf008a01658a63190e93 to your computer and use it in GitHub Desktop.
AJAX demo
var getURL = "http://api.giphy.com/v1/gifs/search?api_key=dc6zaTOxFJmzC&q=cats"
$(document).ready(function(){
// $.post("https://slowpoke-api.now.sh/say", {message: "AJAX sucks"})
// .then(showMessage);
$.get(getURL).then(function(response){
response.data.forEach(function(gif){
var imageElement = createImageTag(gif.images.fixed_height.url);
$("body").append(imageElement);
});
});
});
function showMessage(response){
$(".message").text(response.message);
}
function createImageTag(gifUrl){
return $("<img>").prop("src", gifUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment