Last active
May 28, 2017 00:28
-
-
Save kylecoberly/7035f18c4a7fbf008a01658a63190e93 to your computer and use it in GitHub Desktop.
AJAX demo
This file contains 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
_ |
This file contains 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
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