-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax-store.html
49 lines (48 loc) · 1.71 KB
/
ajax-store.html
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
<!DOCTYPE html>
<html>
<head>
<title>Online Store</title>
</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">refresh</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
(function() {
"use strict";
var inventory = function () {
// TODO: Create an AJAX GET request for the file under data/inventory.json
$.get("data/inventory.json").done(function (data){
// 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
var htmlString = '';
for(var i =0; i < data.length; i++) {
htmlString += '<tr>';
htmlString += '<td>' + data[i].title + '</td>';
htmlString += '<td>' + data[i].quantity + '</td>';
htmlString += '<td>' + data[i].price + '</td>'
htmlString += '<td>' + data[i].categories + '</td>'
htmlString += '</tr>';
}
$('#insertProducts').html(htmlString);
});
}
inventory();
$('#refresh').click(inventory);
})();
</script>
</body>
</html>