mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
Refactor button handling in index.html and app.py
This commit is contained in:
19
src/Python/flask/web/static/script.js
Normal file
19
src/Python/flask/web/static/script.js
Normal file
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user