-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpollBox.html
50 lines (46 loc) · 1.2 KB
/
pollBox.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
<html lang="en">
<head>
<style>
p.question {
margin-bottom: 0.5em;
}
ul.answers {
list-style-type: none;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<section class="poll">
<p class="question">Test</p>
<ul class="answers">
</ul>
</section>
<section class="error"></section>
<script type="text/javascript">
let question = document.querySelector("p.question")
let answers = document.querySelector("ul.answers")
let error = document.querySelector("section.error")
fetchContent()
setInterval(fetchContent, 1000)
function fetchContent() {
fetch("{{ .ApiEndpoint }}")
.then(r => r.json())
.then(r => {
question.innerHTML = r.question
answers.innerHTML = ""
r.answers.forEach(answer => {
let answerNode = document.createElement("li")
answerNode.appendChild(document.createTextNode(answer.label + ": " + answer.count))
answers.appendChild(answerNode)
})
error.innerHTML = ""
})
.catch(err => {
error.innerHTML = err
})
}
</script>
</body>
</html>