Created
October 22, 2017 20:58
-
-
Save ahoef/3203ebce7a0d4ef70466d4c2fbf86f2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function makeRequest(url) { | |
httpRequest = new XMLHttpRequest(); | |
if (!httpRequest) { | |
displayErrorMsg('Sorry, there was a problem making the request!'); | |
return false; | |
} | |
httpRequest.onreadystatechange = receiveRequest; | |
httpRequest.open('GET', url); | |
httpRequest.send(); | |
} | |
function receiveRequest() { | |
if (httpRequest.readyState === XMLHttpRequest.DONE) { | |
if (httpRequest.status === 200) { | |
data = JSON.parse(httpRequest.response); | |
console.log(data); | |
} else { | |
displayErrorMsg('Sorry, there was a problem with the request response!'); | |
} | |
} | |
} | |
window.onload = makeRequest('http://api.giphy.com/v1/gifs/search?q=dog&limit=20&api_key=dc6zaTOxFJmzC'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment