-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders_example.html
More file actions
90 lines (72 loc) · 1.86 KB
/
Copy pathorders_example.html
File metadata and controls
90 lines (72 loc) · 1.86 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
<!DOCTYPE html>
<html>
<head>
<title>Orders</title>
<link rel="shortcut icon" href="about:blank">
<style>
section {
background-color: cornsilk;
border: 2px solid black;
margin-bottom: 5px;
padding: 10px;
}
dt {
font-weight: bold;
}
dd {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Current Orders</h1>
<div id="orders">
<!-- This HTML should be dynamically generated by JS -->
<section>
<h3>Order #x</h3>
<dl>
<dt>Item Ordered</dt>
<dd>Such and such item</dd>
<dt>Ordered by</dt>
<dd>Ordered by such and such</dd>
</dl>
</section>
</div>
<button id="update">Update w/Ajax</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
"use strict";
function updatePage() {
var ajaxRequest = $.ajax("data/orders.json");
ajaxRequest.done(function(data, status, jqXhr) {
console.log("test");
console.log(data);
buildHTML(data);
});
ajaxRequest.fail(function(jqXhr, status, error) {
console.log(jqXhr); // jQuery XMLHttpRequest object
console.log(status);
console.log(error);
});
}
function buildHTML(orders) {
var ordersHTML = "";
orders.forEach(function(order) {
ordersHTML += "<section>";
ordersHTML += "<h3>" + "Order #" + order.orderNumber + "</h3>";
ordersHTML += "<dl>";
ordersHTML += "<dt>" + "Item Ordered" + "</dt>";
ordersHTML += "<dd>" + order.itemOrdered + "</dd>";
ordersHTML += "<dt>" + "Ordered by" + "</dt>";
ordersHTML += "<dd>" + order.orderedBy + "</dd>";
ordersHTML += "</dl>";
ordersHTML += "</section>";
});
$('#orders').html(ordersHTML);
}
$('#update').click(updatePage);
});
</script>
</body>
</html>