attempt to fix javascript

This commit is contained in:
2025-01-06 10:34:00 +01:00
parent 51aad34c78
commit 629f9cba92

View File

@@ -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);
}});
});