-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiDb.html
More file actions
73 lines (62 loc) · 2.15 KB
/
apiDb.html
File metadata and controls
73 lines (62 loc) · 2.15 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One Piece Arcs</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.card {
width: 500px;
}
#data {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
align-items: center;
}
</style>
</head>
<body class="bg-light">
<div class="container my-4">
<button class="btn btn-primary" type="button" onclick="ondisplay()">
Fetch One Piece Arcs
</button>
<div id="data" class="card-group gap-3"></div>
</div>
<script>
const url = "db.json";
function ondisplay() {
fetch(url)
.then(res => res.json())
.then(data => {
let output = "";
data.arcs.forEach(item => {
output += `
<div class="card">
<img src="https://via.placeholder.com/300x180?text=${item.name}"
class <h5 class="card-title">${item.name}</h5>
<p class="card-text">
<strong>Saga:</strong> ${item.saga}<br>
<strong>Episodes:</strong> ${item.episodes}<br>
<strong>Location:</strong> ${item.mainLocation}<br>
<strong>Villain:</strong> ${item.mainVillain}
</p>
</div>
<div class="card-footer">
<small class="text-muted">
Joined: ${item.strawHatsJoined?.join(", ") || "—"}
</small>
</div>
</div>
`;
});
document.getElementById("data").innerHTML = output;
})
.catch(err => console.error("Fetch error:", err));
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>