From 3d6842f4944f8231dbbb7e1afbfbc74f924b4022 Mon Sep 17 00:00:00 2001 From: raheemahdana Date: Tue, 26 Jan 2021 21:44:21 -0500 Subject: [PATCH 1/2] Completed Ajax Lab --- .vscode/launch.json | 15 +++++++++++++++ Ajax.html | 14 ++++++++++++++ Ajax.js | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 Ajax.html create mode 100644 Ajax.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a9dfa0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Ajax.html b/Ajax.html new file mode 100644 index 0000000..50af8e8 --- /dev/null +++ b/Ajax.html @@ -0,0 +1,14 @@ + + + + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/Ajax.js b/Ajax.js new file mode 100644 index 0000000..159117b --- /dev/null +++ b/Ajax.js @@ -0,0 +1,15 @@ + +let xhr = new XMLHttpRequest +xhr.onreadystatechange= function(){ + if (xhr.readyState=== 4 && xhr.status ===200){ + let data =JSON.parse(xhr.responseText); + let image=``; + document.getElementById("ajax").innerHTML=image; + + } +} +xhr.open ("GET","https://dog.ceo/api/breeds/image/random"); +function fetch(){ + +xhr.send(); +} \ No newline at end of file From 504b52dc4e2c215892de830cf8766add3261a94a Mon Sep 17 00:00:00 2001 From: raheemahdana Date: Wed, 3 Feb 2021 17:55:25 -0500 Subject: [PATCH 2/2] Completed Ajax Project now shows 3 Dogs --- Ajax.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Ajax.js b/Ajax.js index 159117b..a7dcafc 100644 --- a/Ajax.js +++ b/Ajax.js @@ -2,13 +2,17 @@ let xhr = new XMLHttpRequest xhr.onreadystatechange= function(){ if (xhr.readyState=== 4 && xhr.status ===200){ - let data =JSON.parse(xhr.responseText); - let image=``; - document.getElementById("ajax").innerHTML=image; - + let data =JSON.parse(xhr.responseText); + let image; + for(let i=0;i<3;i++){ + image =``; //accessing each index in the message array of the json file + document.getElementById("ajax").innerHTML += image; //concatenating so that each old image is not replaced by the new image + // same as saying: + //document.getElementById("ajax").innerHTML = `` + } } } -xhr.open ("GET","https://dog.ceo/api/breeds/image/random"); +xhr.open ("GET","https://dog.ceo/api/breeds/image/random/3"); function fetch(){ xhr.send();