-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-api-table.html
More file actions
63 lines (48 loc) · 1.85 KB
/
Copy pathfetch-api-table.html
File metadata and controls
63 lines (48 loc) · 1.85 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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<title>User Data Table</title>
</head>
<body>
<table class="table" id="userTable">
<thead class="thead-light">
<tr>
<th>Name</th>
<th>Email</th>
<th>Zipcode</th>
</tr>
</thead>
<tbody id="userTableBody">
</tbody>
</table>
<script>
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(data => {
var tableBody = document.getElementById("userTableBody")
data.forEach(user => {
const tr = document.createElement('tr');
const td = document.createElement('td');
const td2 = document.createElement('td');
const td3 = document.createElement('td');
console.log(data);
td.textContent = user.name;
td2.textContent = user.email;
td3.textContent = user.address.zipcode;
tr.appendChild(td);
tr.appendChild(td2);
tr.appendChild(td3);
tableBody.appendChild(tr);
});
})
.catch(error => { console.error(error); });
</script>
</body>
</html>