-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-api2.html
More file actions
62 lines (48 loc) · 1.47 KB
/
Copy pathfetch-api2.html
File metadata and controls
62 lines (48 loc) · 1.47 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
<!DOCTYPE html>
<html>
<head>
<title>User Data Table</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<table class="table">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Zipcode</th>
</tr>
</thead>
<tbody id="TableBody" class="table-bordered">
</tbody>
</table>
</div>
<script>
fetch('https://jsonplaceholder.typicode.com/users')
.then(res => res.json())
.then((data) => {
const tbody = document.getElementById("TableBody")
data.forEach(element => {
const trow = document.createElement("tr");
tbody.appendChild(trow);
const id = document.createElement("td")
id.innerHTML = element.id;
tbody.appendChild(id)
const name = document.createElement("td")
name.innerHTML = element.name;
tbody.appendChild(name)
const email = document.createElement("td")
email.innerHTML = element.email;
tbody.appendChild(email)
const ZipCode = document.createElement("td")
ZipCode.innerHTML = element.address.zipcode;
tbody.appendChild(ZipCode)
});
}
)
.catch(error => { console.error(error); });
</script>
</body>
</html>