mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
started with fetch
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
document.querySelectorAll('button').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const direction = this.value;
|
||||
fetch('/move', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams({ direction: direction }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('response').innerText = data.message;
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('response').innerText = 'Er is een fout opgetreden: ' + error;
|
||||
});
|
||||
});
|
||||
});
|
||||
window.onload = function () {
|
||||
const form = document.getElementById("form");
|
||||
form.onclick = function (event) {
|
||||
event.preventDefault();
|
||||
fetch("/move", {
|
||||
method: "GET",
|
||||
})
|
||||
.then((response) => {})
|
||||
.then(() => {
|
||||
fetch
|
||||
});
|
||||
};
|
||||
};
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<img src="kobuki.jpg" alt="Kobuki Robot" id="robot-image" />
|
||||
</div>
|
||||
<div class="button-section">
|
||||
<form action="/" method="post">
|
||||
<form id = "form" action="/" method="post">
|
||||
<button class="btn" name="direction" value="left">←</button>
|
||||
<button class="btn" name="direction" value="up">↑</button>
|
||||
<button class="btn" name="direction" value="right">→</button>
|
||||
|
Reference in New Issue
Block a user