JSON is shown on website
This commit is contained in:
parent
73f637d6ec
commit
ca811a9abe
@ -6,8 +6,24 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function onBodyLoad(){
|
function onBodyLoad(){
|
||||||
const xhttp = new XMLHttpRequest();
|
const xhttp = new XMLHttpRequest();
|
||||||
|
xhttp.responseType = 'json';
|
||||||
xhttp.onload = function() {
|
xhttp.onload = function() {
|
||||||
document.getElementById("debug").innerHTML = this.responseText;
|
var jsonResponse = this.response;
|
||||||
|
document.getElementById("temp").innerHTML = jsonResponse.temp
|
||||||
|
document.getElementById("altitude").innerHTML = jsonResponse.altitude;
|
||||||
|
document.getElementById("pressure").innerHTML = jsonResponse.pressure;
|
||||||
|
document.getElementById("particle").innerHTML = jsonResponse.particle;
|
||||||
|
if (jsonResponse.gas) {
|
||||||
|
document.getElementById("gas").innerHTML = jsonResponse.gas;
|
||||||
|
} else {
|
||||||
|
document.getElementById("rowGas").hidden = true;
|
||||||
|
}
|
||||||
|
if (jsonResponse.humidity) {
|
||||||
|
document.getElementById("humidity").innerHTML = jsonResponse.humidity;
|
||||||
|
} else {
|
||||||
|
document.getElementById("rowHumidity").hidden = true;
|
||||||
|
}
|
||||||
|
console.log(this.responseText);
|
||||||
}
|
}
|
||||||
xhttp.open("GET", "/sensors", true);
|
xhttp.open("GET", "/sensors", true);
|
||||||
xhttp.send();
|
xhttp.send();
|
||||||
@ -17,11 +33,14 @@
|
|||||||
<body id="body" onload="onBodyLoad()">
|
<body id="body" onload="onBodyLoad()">
|
||||||
<h1>Room Sensor</h1>
|
<h1>Room Sensor</h1>
|
||||||
<table>
|
<table>
|
||||||
<th>
|
<thead>
|
||||||
|
<tr>
|
||||||
<td>Sensor</td>
|
<td>Sensor</td>
|
||||||
<td>Value</td>
|
<td>Value</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</th>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Temperatur</td>
|
<td>Temperatur</td>
|
||||||
<td id="temp">temp</td>
|
<td id="temp">temp</td>
|
||||||
@ -52,7 +71,7 @@
|
|||||||
<td id="particle">particle</td>
|
<td id="particle">particle</td>
|
||||||
<td>micro gram per quibik</td>
|
<td>micro gram per quibik</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p id="debug">Nothing</p>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user