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() }) }) })