fixed error from braces

This commit is contained in:
ishak jmilou.ishak
2024-12-18 12:42:15 +01:00
parent 29cfa86b5f
commit ddeeb379cf

View File

@@ -1,6 +1,6 @@
// Selecteer alle knoppen en voeg een event listener toe aan elke knop
document.querySelectorAll(".btn").forEach(button => {
button.addEventListener("click", function(event) {
document.querySelectorAll(".btn").forEach((button) => {
button.addEventListener("click", function (event) {
event.preventDefault(); // voorkomt pagina-verversing
// Haal de waarde van de knop op
@@ -9,30 +9,30 @@ document.querySelectorAll(".btn").forEach(button => {
fetch("/move", {
method: "POST",
headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},
body: JSON.stringify({ direction: direction })
body: JSON.stringify({ direction: direction }),
})
.then(response => response.json())
.then(data => {
console.log("Success:", data);
})
.catch(error => {
console.error("Error:", error);
});
.then((response) => response.json())
.then((data) => {
console.log("Success:", data);
})
.catch((error) => {
console.error("Error:", error);
});
});
// 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
async function parseData() {
const data = await fetchData();
@@ -48,4 +48,4 @@ document.querySelectorAll(".btn").forEach(button => {
// Fetch and display sensor data every 5 seconds
setInterval(parseData, 5000);
});
});