From cdbdc9278fe9bee753f530c3630fe5b889fa0500 Mon Sep 17 00:00:00 2001 From: Override-6 Date: Fri, 25 Nov 2022 19:55:58 +0100 Subject: [PATCH] First interface test with a counter increment --- www/counter/index.html | 18 ++++++++++++++++++ www/counter/index.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 www/counter/index.html create mode 100644 www/counter/index.js diff --git a/www/counter/index.html b/www/counter/index.html new file mode 100644 index 0000000..c532488 --- /dev/null +++ b/www/counter/index.html @@ -0,0 +1,18 @@ + + + + + + Counter + + + +
+ + + +
+ + + + \ No newline at end of file diff --git a/www/counter/index.js b/www/counter/index.js new file mode 100644 index 0000000..6200005 --- /dev/null +++ b/www/counter/index.js @@ -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() + }) +}