-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax-store.html
More file actions
98 lines (81 loc) · 2.4 KB
/
ajax-store.html
File metadata and controls
98 lines (81 loc) · 2.4 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>Online Store</title>
<!-- CSS-->
<style>
h1 {
text-align: center;
color: white;
}
table, tr, th {
margin: auto;
border: 1px solid black;
padding: 20px;
background-color: whitesmoke;
}
th {
background-color: lightyellow;
}
button {
display: flex;
margin: auto;
margin-top: 2em;
background-color: lightblue;
}
body {
background-image: url("img/photo-1534190239940-9ba8944ea261.jpeg");
}
</style>
<!--HTML-->
</head>
<body>
<h1>My Tool Store</h1>
<table id="products">
<thead>
<tr>
<th>Title</th>
<th>Quantity</th>
<th>Price</th>
<th>Categories</th>
</tr>
</thead>
<tbody id="insertProducts"></tbody>
</table>
<button id="refresh" type="button">refresh</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--JavaScript-->
<script>
(function () {
"use strict";
// TODO: Create an AJAX GET request for the file under data/inventory.json
$(document).ready(function () {
$.get("data/inventory.json")
.done(handlerResponse);
})
// 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
function handlerResponse(tools) {
let html = "";
console.log(tools);
tools.forEach(function (tool) {
html += "<tr>"
html += "<th>" + tool.title + "</th>"
html += "<th>" + tool.quantity + "</th>"
html += "<th>" + tool.price + "</th>"
html += "<th>" + tool.categories + "</th>"
html += "</tr>"
});
$("#insertProducts").html(html);
}
$("#refresh").click(function () {
$.get("data/inventory.json")
.done(handlerResponse);
})
})();
</script>
</body>
</html>