First interface test with a counter increment

production
Override-6 2 years ago
parent e2a2bed6e2
commit cdbdc9278f

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="index.js"></script>
<title>Counter</title>
</head>
<body onload="initCounter()">
<div id="page">
<label>Compteur : </label>
<label id="counter">{0}</label>
<button id="increment" onclick="makeIncrement()">Incrémenter</button>
</div>
<script src="/cordova.js"></script>
</body>
</html>

@ -0,0 +1,28 @@
let counter = 0;
function updateText() {
document.getElementById("counter").innerHTML = counter
}
async function makeIncrement() {
fetch("http://localhost:48485/counter", {method: 'POST'})
.then(response => { //TODO verify if it's not an error
counter++
updateText()
})
}
function initCounter() {
fetch("http://localhost:48485/counter", {method: 'GET'})
.then(response => {
if (response.ok) {
console.log("response is ok")
}
console.log(response)
return response.json()
})
.then(json => {
counter = json.value
updateText()
})
}