-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
38 lines (31 loc) · 888 Bytes
/
test.html
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
38
<!-- Pequeño código para probar el link de las fotos -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visualización de una imagen</title>
</head>
<body>
<div id="image-container">
<img id="image" src="" alt="Imagen">
</div>
<script>
window.onload = function() {
var productUrl = "https://api.escuelajs.co/api/v1/products/5";
var xhrProduct = new XMLHttpRequest();
xhrProduct.open("GET", productUrl, true);
xhrProduct.setRequestHeader("Accept", "*/*");
xhrProduct.onload = function() {
if (this.status === 200) {
var productData = JSON.parse(this.responseText);
var imageUrl = productData.images[1];
var imageElement = document.getElementById("image");
imageElement.src = imageUrl;
}
};
xhrProduct.send();
};
</script>
</body>
</html>