-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-haku-iot.html
More file actions
60 lines (47 loc) · 1.64 KB
/
Copy pathapi-haku-iot.html
File metadata and controls
60 lines (47 loc) · 1.64 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
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<html>
<body style="margin-left: 100px">
<h2>Mittausdataa</h2>
<br>
<button onclick="haeData()">Päivitä</button>
<br><br>
<div id="htmlTaulukko"></div>
<script>
function haeData() {
document.getElementById("htmlTaulukko").innerHTML = `<marquee direction = "up"><h2>Haetaan mittaustuloksia...</h2></marquee>`
var mittausTable = `<table style="width: 500px">
<thead>
<tr>
<th>Sender</th>
<th>Time</th>
<th>Temperature</th>
<th>Humidity</th>
<th>Pressure</th>
</tr>
</thead>
<tbody>`
fetch('https://timesheetrest.azurewebsites.net/api/measurements/')
.then(response => response.json())
.then(json => json.map(m =>
mittausTable += `<tr>
<td>${m.sender}</td>
<td>${m.time}</td>
<td>${m.temperature}</td>
<td>${m.humidity}</td>
<td>${m.pressure}</td>
</tr>`
))
// Palvelimen vastaus kestää ja siksi koodi ei toimi
// jos ei odota dataa hetken ennenkuin päättää taulukon. Nyt 4000ms = 4sek.
setTimeout(() => {
mittausTable += `</tbody></table>`
document.getElementById("htmlTaulukko").innerHTML = mittausTable
}, 4000
)
}
</script>
</body>
</html>