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 () {
|
||||
const form = document.getElementById("form");
|
||||
form.onclick = function (event) {
|
||||
event.preventDefault();
|
||||
fetch("/move", {
|
||||
method: "GET",
|
||||
document.getElementById("form").addEventListener("click", function(event) {
|
||||
event.preventDefault(); // Prevent the form from reloading the page
|
||||
|
||||
// Check if the target of the click event is a button
|
||||
if (event.target.tagName === "BUTTON") {
|
||||
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(() => {
|
||||
fetch
|
||||
});
|
||||
};
|
||||
};
|
||||
9
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log("Success:", data);
|
||||
// Optional: Update UI based on server response if needed
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user