From 80771dc7402fa3625759d35a41f797ce81d861ee Mon Sep 17 00:00:00 2001 From: "ishak jmilou.ishak" Date: Thu, 24 Oct 2024 13:23:37 +0200 Subject: [PATCH] started with fetch --- src/Python/flask/web/static/script.js | 32 +++++++++-------------- src/Python/flask/web/templates/index.html | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Python/flask/web/static/script.js b/src/Python/flask/web/static/script.js index 1e1f33c..2499630 100644 --- a/src/Python/flask/web/static/script.js +++ b/src/Python/flask/web/static/script.js @@ -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; - }); - }); -}); \ No newline at end of file +window.onload = function () { + const form = document.getElementById("form"); + form.onclick = function (event) { + event.preventDefault(); + fetch("/move", { + method: "GET", + }) + .then((response) => {}) + .then(() => { + fetch + }); + }; +}; diff --git a/src/Python/flask/web/templates/index.html b/src/Python/flask/web/templates/index.html index eb6d459..705c2ed 100644 --- a/src/Python/flask/web/templates/index.html +++ b/src/Python/flask/web/templates/index.html @@ -12,7 +12,7 @@ Kobuki Robot
-
+