-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (51 loc) · 1.55 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
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<button id="start-btn">Start</button>
<button id="stop-btn">stop</button>
<div id="status-message"></div>
</body>
<script>
function updateStatus(statusMessage) {
document.getElementById("status-message").innerText = statusMessage;
}
function sendRequestToFlaskServer(status, successCallBack, errorCallBack) {
return fetch('http://127.0.0.1:5000/?status=' + status).then(function (response) {
// The API call was successful!
return response.json();
}).then(function (data) {
// This is the JSON from our response
console.log(data);
successCallBack(data)
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
errorCallBack(err)
});
}
function successCallBack(response) {
console.log(response)
updateStatus(response.message);
}
function errorCallBack(response) {
updateStatus(response.message);
}
function startMachine() {
sendRequestToFlaskServer(1, successCallBack, errorCallBack);
}
function stopMachine() {
sendRequestToFlaskServer(0, successCallBack, errorCallBack);
}
document.getElementById("start-btn").onclick = function () {
startMachine();
}
document.getElementById("stop-btn").onclick = function () {
stopMachine();
}
</script>
</html>