-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.html
53 lines (48 loc) · 1.38 KB
/
index.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
50
51
52
53
<!DOCTYPE html>
<html>
<head>
<title>Ship Money!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
// Query the current value of the account
$("#queryAccount").click(function() {
$.ajax({
dataType: 'json',
url: 'http://localhost:3000/state/account',
success: function(data, status) {
console.log(data);
document.getElementById("accountValue").innerHTML = "Account ($): " + data.value;
}
});
});
// Add a given number of units to the account value
$("#donate").click(function() {
var amount = $("input").val();
console.log("donation amount = " + amount);
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
},
type: "POST",
url: 'http://localhost:3000/transactions',
data: JSON.stringify({ "amount": amount }),
dataType: "json",
success: function(result) {
console.log("Status: " + result.status);
}
});
});
});
</script>
</head>
<body>
<button id="queryAccount">Get Account Value</button>
<p id="accountValue"></p>
Donation Amount ($):
<input type="text">
<button id="donate">Donate</button>
<p id="donationResult"></p>
</body>
</html>