forked from danielscarvalho/FTT-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesteImgApiV2.html
More file actions
34 lines (29 loc) · 750 Bytes
/
Copy pathTesteImgApiV2.html
File metadata and controls
34 lines (29 loc) · 750 Bytes
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
<html>
<head>
<style>
li {list-style-type: none;}
img {width:300px;}
</style>
<script>
function setImage(msg) {
console.log(msg); //Só para debug!!
liTag = document.createElement("li");
imgTag = document.createElement("img");
imgTag.src = msg["message"];
liTag.appendChild(imgTag);
document.getElementById("dogList").appendChild(liTag);
}
function getImageInfo() {
fetch("https://dog.ceo/api/breeds/image/random") //WEB API - HTTP
.then(request => request.text()) //Retorna o objeto request
.then(data => setImage(JSON.parse(data))) //Obtem os dados e transforma em JSON
}
</script>
</head>
<body>
<button onclick="getImageInfo();">Get Image</button>
<hr>
<ul id="dogList">
</ul>
</body>
</html>