mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
fixed fetch
This commit is contained in:
@@ -1,14 +1,25 @@
|
|||||||
window.onload = function () {
|
document.getElementById("form").addEventListener("click", function(event) {
|
||||||
const form = document.getElementById("form");
|
event.preventDefault(); // Prevent the form from reloading the page
|
||||||
form.onclick = function (event) {
|
|
||||||
event.preventDefault();
|
// Check if the target of the click event is a button
|
||||||
fetch("/move", {
|
if (event.target.tagName === "BUTTON") {
|
||||||
method: "GET",
|
const direction = event.target.value; // Get the direction from the button's value
|
||||||
|
|
||||||
|
// Send the direction data to the server using fetch
|
||||||
|
fetch("/", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ direction: direction })
|
||||||
})
|
})
|
||||||
.then((response) => {})
|
.then(response => response.json())
|
||||||
.then(() => {
|
.then(data => {
|
||||||
fetch
|
console.log("Success:", data);
|
||||||
|
// Optional: Update UI based on server response if needed
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error:", error);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
};
|
});
|
||||||
9
|
|
||||||
|
Reference in New Issue
Block a user