From 629f9cba9270265d573b65675f2241985e65cfb8 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Mon, 6 Jan 2025 10:34:00 +0100 Subject: [PATCH] attempt to fix javascript --- src/Python/flask/web/static/script.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Python/flask/web/static/script.js b/src/Python/flask/web/static/script.js index 1806d11..c81bc7b 100644 --- a/src/Python/flask/web/static/script.js +++ b/src/Python/flask/web/static/script.js @@ -14,7 +14,7 @@ document.addEventListener("DOMContentLoaded", function() { body: JSON.stringify({ direction: direction }) }) .then(response => response.json()) - .then(data => {script + .then(data => { console.log("Success:", data); }) .catch(error => { @@ -25,12 +25,13 @@ document.addEventListener("DOMContentLoaded", function() { // Fetch data from the server async function fetchData() { - try{ - const response = await fetch("/data"); - const data = await response.json(); - return data; - } catch (error) { - console.error("Error:", error); + try { + const response = await fetch("/data"); + const data = await response.json(); + return data; + } catch (error) { + console.error("Error:", error); + } } // Parse the data and show it on the website @@ -52,9 +53,9 @@ document.addEventListener("DOMContentLoaded", function() { img.src = "/image?" + new Date().getTime(); // Add timestamp to avoid caching } - // Fetch and display sensor data every 5 seconds + // Fetch and display sensor data every 1 second setInterval(parseData, 1000); - // Update the image every 5 seconds + // Update the image every 200 milliseconds setInterval(updateImage, 200); -}}); \ No newline at end of file +}); \ No newline at end of file