Created
August 29, 2019 16:43
-
-
Save MajhiRockzZ/85cc574a66c90c358541c038b97a3ade to your computer and use it in GitHub Desktop.
AJAX JSON FETCH
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
const DOG_URL = "https://dog.ceo/api/breeds/image/random"; | |
// console.log(DOG_URL); | |
// const promise = fetch(DOG_URL); | |
const doggos = document.querySelector(".doggos"); | |
// console.log(promise); | |
function addNewDoggo() { | |
const promise = fetch(DOG_URL); | |
promise | |
.then(function(response) { | |
const processingPromise = response.json(); | |
// console.log(processingPromise); | |
return processingPromise; | |
}) | |
.then(function(processedResponse) { | |
// console.log(processedResponse.status); | |
console.log(processedResponse); | |
const img = document.createElement("img"); | |
img.src = processedResponse.message; | |
img.alt = "Cute doggo"; | |
doggos.appendChild(img); | |
}); | |
} | |
document.querySelector(".add-doggo").addEventListener("click", addNewDoggo); | |
// console.log("this will log first"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment