Skip to content

Instantly share code, notes, and snippets.

@ahoef
Created October 22, 2017 20:58
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 ahoef/3203ebce7a0d4ef70466d4c2fbf86f2a to your computer and use it in GitHub Desktop.
Save ahoef/3203ebce7a0d4ef70466d4c2fbf86f2a to your computer and use it in GitHub Desktop.
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