-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax-store.html
More file actions
70 lines (68 loc) · 2.52 KB
/
ajax-store.html
File metadata and controls
70 lines (68 loc) · 2.52 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Online Store</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="jquery-3.6.0.js"></script>
<style>
body{
background: #fcfbc9;
}
</style>
</head>
<body class="text-primary">
<h1 class="text-center">My Tool Store</h1>
<br>
<div class="d-flex justify-content-center">
<table id="products" class="text-center">
<thead>
<tr>
<th>Title</th>
<th>Quantity</th>
<th>Price</th>
<th>Categories</th>
</tr>
</thead>
<tbody id="insertProducts"></tbody>
</table>
</div>
<br>
<div class="text-center">
<button id="refresh" class="text-primary">Refresh</button>
</div>
<script src="jquery-3.6.0.js"></script>
<script>
(function() {
"use strict";
$('#refresh').click(()=> inventoryData())
// TODO: Create an AJAX GET request for the file under data/inventory.json
function inventoryData() {
$.get('data/inventory.json').done(function (data) {
$('#insertProducts').empty()
console.log(data)
data.forEach(function (product) {
let html = '';
html += '<tr>';
html += '<td class="px-5">' + product.title + '</td>';
html += '<td class="px-5">' + product.quantity + '</td>';
html += '<td class="px-5">' + product.price.toFixed(2) + '</td>';
html += '<td class="px-5">' + product.categories.join(', ') + '</td>';
html += '</tr>';
$('#insertProducts').append(html)
})
})
}
inventoryData()
// TODO: Take the data from inventory.json and append it to the products table
// HINT: Your data should come back as a JSON object; use console.log() to inspect
// its contents and fields
// HINT: You will want to target #insertProducts for your new HTML elements
})();
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
</script>
</body>
</html>