From 2e64feebd5a95217eafcac6bd061016dc0c98ef8 Mon Sep 17 00:00:00 2001 From: Denae716 Date: Fri, 29 Jan 2021 18:41:15 -0500 Subject: [PATCH 1/4] part1 --- ajax.html | 11 +++++++++++ ajax.js | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 ajax.html create mode 100644 ajax.js diff --git a/ajax.html b/ajax.html new file mode 100644 index 0000000..30d9c13 --- /dev/null +++ b/ajax.html @@ -0,0 +1,11 @@ + + + + + + Dog API + + + + + \ No newline at end of file diff --git a/ajax.js b/ajax.js new file mode 100644 index 0000000..095b1b0 --- /dev/null +++ b/ajax.js @@ -0,0 +1,11 @@ + + + +let xhr = new XMLHttpRequest(); +xhr.onreadystatechange = function (){ + if(this.readyState === 4 && this.status === 200){ + console.log(xhr.responseText) + } +} +xhr.open('GET', 'https://dog.ceo/api/breeds/image/random'); +xhr.send(); \ No newline at end of file From d52f738b1293dbaf6e839c4b454643207814b4cd Mon Sep 17 00:00:00 2001 From: Denae716 Date: Fri, 29 Jan 2021 19:29:32 -0500 Subject: [PATCH 2/4] works for only the 1st time fetch is clicked --- ajax.html | 6 +++++- ajax.js | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ajax.html b/ajax.html index 30d9c13..00e47a9 100644 --- a/ajax.html +++ b/ajax.html @@ -6,6 +6,10 @@ Dog API - +
+ + +
+ \ No newline at end of file diff --git a/ajax.js b/ajax.js index 095b1b0..58e8498 100644 --- a/ajax.js +++ b/ajax.js @@ -1,11 +1,21 @@ -let xhr = new XMLHttpRequest(); + +let xhr = new XMLHttpRequest xhr.onreadystatechange = function (){ - if(this.readyState === 4 && this.status === 200){ - console.log(xhr.responseText) +if (this.readyState === 4 && this.status === 200){ + + let data =JSON.parse(this.response) + console.log(data) + document.getElementById("image").src = data.message + + } } + xhr.open('GET', 'https://dog.ceo/api/breeds/image/random'); -xhr.send(); \ No newline at end of file +let fetch = function(){ +xhr.send(); + +} From f379bfe95e32842593bff521ddb6fb42b398945e Mon Sep 17 00:00:00 2001 From: Denae716 Date: Fri, 29 Jan 2021 19:38:03 -0500 Subject: [PATCH 3/4] working for 1 pic --- ajax.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ajax.js b/ajax.js index 58e8498..d004c9e 100644 --- a/ajax.js +++ b/ajax.js @@ -13,9 +13,8 @@ if (this.readyState === 4 && this.status === 200){ } } - -xhr.open('GET', 'https://dog.ceo/api/breeds/image/random'); let fetch = function(){ +xhr.open('GET', 'https://dog.ceo/api/breeds/image/random', true); xhr.send(); } From ce47356e654a71ac4e70685fa293c6bcf1f0649f Mon Sep 17 00:00:00 2001 From: Denae716 Date: Fri, 29 Jan 2021 19:41:46 -0500 Subject: [PATCH 4/4] 3 pups at a time --- ajax.html | 4 +++- ajax.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ajax.html b/ajax.html index 00e47a9..3f79883 100644 --- a/ajax.html +++ b/ajax.html @@ -7,7 +7,9 @@
- + + +
diff --git a/ajax.js b/ajax.js index d004c9e..d689ac9 100644 --- a/ajax.js +++ b/ajax.js @@ -8,13 +8,15 @@ if (this.readyState === 4 && this.status === 200){ let data =JSON.parse(this.response) console.log(data) - document.getElementById("image").src = data.message + document.getElementById("image1").src = data.message[0] + document.getElementById("image2").src = data.message[1] + document.getElementById("image3").src = data.message[2] } } let fetch = function(){ -xhr.open('GET', 'https://dog.ceo/api/breeds/image/random', true); +xhr.open('GET', 'https://dog.ceo/api/breeds/image/random/3', true); xhr.send(); }