-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom_Dog.html
More file actions
37 lines (35 loc) · 1.04 KB
/
Random_Dog.html
File metadata and controls
37 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>get dog</title>
</head>
<body>
<h1>DOG IMAGE</h1>
<div>
<button id="getDogBtn">GET DOG IMAGE</button>
</div>
<hr />
<div>
<img id="dogImage" style="display: none" alt="random-dog-image" />
</div>
<!-- script -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
const dogImage = document.querySelector("#dogImage");
const getDogBtn = document.querySelector("#getDogBtn");
getDogBtn.addEventListener("click", function (event) {
axios
.get("https://dog.ceo/api/breeds/image/random") // axios.get() 리턴값은 promise
.then(function (res) {
const dogUrl = res.data.message; // axios 사용시, res.data 까지는 고정
dogImage.src = dogUrl;
dogImage.style.display = "block";
})
.catch(function (err) {
console.error(err);
});
});
</script>
</body>
</html>