mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
24 lines
688 B
JavaScript
24 lines
688 B
JavaScript
document.getElementById("form").addEventListener("submit", function(event) {
|
|
event.preventDefault(); // voorkomt het herladen van de pagina
|
|
|
|
// Haal de waarde van de ingedrukte knop op
|
|
const formData = new FormData(event.target);
|
|
const direction = formData.get("direction"); // Haalt de 'direction' waarde op
|
|
|
|
// 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);
|
|
});
|
|
});
|