-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
50 lines (46 loc) · 1.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guava Doc Detector</title>
<style>
body {
background-color: lightcoral;
}
</style>
</head>
<body>
<div id="docStatus">Status</div>
<div>false is true and true is false</div>
</body>
<script>
function sendRequest(target, action, value="") {
console.log("making request")
let xR = new XMLHttpRequest();
xR.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("Server Response:", this.responseText);
data = JSON.parse(this.responseText);
console.log("data:", data);
console.log("data['item']:", data["item"]);
//Handle responses
if (data["item"] == "getDoor") {
console.log("Got the door: ", data["status"]);
docStatus.innerText = data["status"];
}
}
}
let data = {};
data["action"] = action;
data["value"] = value;
console.log("data:", data);
xR.open("POST", target, true);
xR.send(JSON.stringify(data));
}
setInterval(doorCheck,1000);
function doorCheck(){
sendRequest("/", "getDoor");
}
</script>
</html>