From b35221a086182117b30534740a421d9a3b797bef Mon Sep 17 00:00:00 2001 From: konradm Date: Wed, 13 Nov 2024 14:47:17 +0100 Subject: [PATCH] obliczanie dziala, dodanie posta --- index.html | 20 ++++++++++++++++---- js/post.js | 26 ++++++++++++++++++++++++++ js/script.js | 13 +++++++++++++ php/gget.php | 2 +- php/post.php | 20 ++++++++++++++++++++ token.txt | 1 + 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 js/post.js create mode 100644 php/post.php create mode 100644 token.txt diff --git a/index.html b/index.html index 771e794..08b17e5 100644 --- a/index.html +++ b/index.html @@ -31,10 +31,11 @@ - - - - + Ile litrow?
+
+ + +

@@ -43,9 +44,20 @@ +
+

Dodaj rodzaj paliwa

+ Nazwa:
+

+ Cena:
+

+ +
+ + + diff --git a/js/post.js b/js/post.js new file mode 100644 index 0000000..5129fda --- /dev/null +++ b/js/post.js @@ -0,0 +1,26 @@ +document.addEventListener('DOMContentLoaded', () => { + + button_dodaj = document.getElementById("button_dodaj") + + button_dodaj.addEventListener("click", () => { + + data = { + nazwa: document.getElementById("name").value, + cena: document.getElementById("price").value + } + fetch("php/post.php", { + method: "POST", + headers: { + "Content-Type":"application/json", + }, + body: JSON.stringify(data) + }) + .then(response => response.json) + .then(data => { + console.log("Succes", data) + window.location.reload() + }) + + }) + +}) diff --git a/js/script.js b/js/script.js index 7225a75..1f2c7e5 100644 --- a/js/script.js +++ b/js/script.js @@ -4,6 +4,7 @@ const cena = document.getElementById("cena"); let usersData = []; + document.addEventListener('DOMContentLoaded', function() { fetch('php/gget.php') .then(response => response.json()) @@ -40,3 +41,15 @@ fuelType.addEventListener('change', function() { } }); +document.getElementById("oblicz").addEventListener("click", () => { + const ile_litrow = document.getElementById("ile_litrow").value + const cena_paliwa = document.getElementById("cena").innerHTML + console.log(ile_litrow) + console.log(cena_paliwa) + + const wynik = ile_litrow * cena_paliwa + + console.log(wynik) + + document.getElementById("wynik").innerHTML = wynik +}) \ No newline at end of file diff --git a/php/gget.php b/php/gget.php index 2706976..3bbe510 100644 --- a/php/gget.php +++ b/php/gget.php @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/token.txt b/token.txt new file mode 100644 index 0000000..3423d94 --- /dev/null +++ b/token.txt @@ -0,0 +1 @@ +03abdf5412e60673d79cd8929fdd18a8bbb631b3