-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.html
44 lines (38 loc) · 1.06 KB
/
10.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
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8' />
<title>DOM FETCH EXAMPLE</title>
<script>
function print(e, m) {
document.getElementById(e).innerHTML += `<div>${m}</div>`;
}
function doCommand(c) {
fetch(c)
.then(response => response.text())
.then(text => print("event_log", text))
.catch(e => print("event_log", `Request Failed: ${e}`));
}
function newButton(n, c) {
let b = document.createElement("BUTTON");
b.onclick = c;
b.appendChild(document.createTextNode(n));
return b;
}
window.onload = () => {
let button_bar = document.getElementById("action_buttons");
{{range $c, $v := .Commands}}
button_bar.appendChild(
newButton('{{$c}}', () => doCommand('{{$c}}')));
{{end}}
};
</script>
</head>
<body>
<h1>DOM FETCH EXAMPLE</h1>
<h2>Known Asynchronous Actions</h2>
<div id="action_buttons"></div>
<h2>Server Output</h2>
<div id='event_log'></div>
</body>
</html>