diff --git a/src/Python/flask/web/static/script.js b/src/Python/flask/web/static/script.js index e751090..197750a 100644 --- a/src/Python/flask/web/static/script.js +++ b/src/Python/flask/web/static/script.js @@ -1,23 +1,25 @@ -document.getElementById("form").addEventListener("submit", function(event) { - event.preventDefault(); // voorkomt het herladen van de pagina +// Selecteer alle knoppen en voeg een event listener toe aan elke knop +document.querySelectorAll(".btn").forEach(button => { + button.addEventListener("click", function(event) { + event.preventDefault(); // voorkomt pagina-verversing - // Haal de waarde van de ingedrukte knop op - const formData = new FormData(event.target); - const direction = formData.get("direction"); // Haalt de 'direction' waarde op + // Haal de waarde van de knop op + const direction = event.target.value; - // Verstuur de richting via fetch naar de server - fetch("/move", { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ direction: direction }) - }) - .then(response => response.json()) - .then(data => { - console.log("Success:", data); - }) - .catch(error => { - console.error("Error:", error); + // Verstuur de richting naar de server met fetch + fetch("/send-direction", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ direction: direction }) + }) + .then(response => response.json()) + .then(data => { + console.log("Success:", data); + }) + .catch(error => { + console.error("Error:", error); + }); }); });