Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dog-jq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="dog-jq.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<div id='buttonclick'>
<button>click for dog</button>
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions dog-jq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//completed using jquery
$(document).ready(function(){
$('#buttonclick').on('click','button',function(){
$.ajax('https://dog.ceo/api/breeds/image/random/3',{
success: function(response){
for (let i=0; i<3; i++) {
$('#buttonclick').append(`<img src=${response.message[i]}>`)
}
}
})
})
});
11 changes: 11 additions & 0 deletions dog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Random Dogs</title>
<script src="dog.js"></script>
</head>
<body>
<button id="revealBtn" onclick="sendAJAX()">Release the dog!</button><br>
<div id="dog-div"></div>
</body>
</html>
23 changes: 23 additions & 0 deletions dog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//completed using vanilla js
function createImg() {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
const response = JSON.parse(xhr.responseText);
let img;
for (let i=0; i<3; i++) {
img = `<img src="${response.message[i]}">`;
document.getElementById('dog-div').innerHTML = img + document.getElementById('dog-div').innerHTML;
}
}
console.log(xhr);
console.log(response.message);
};

xhr.open('GET', 'https://dog.ceo/api/breeds/image/random/3');
xhr.send();
}

function sendAJAX() {
createImg();
}