From 993b26acdcb9f36e6f478790c9104e52250f4c83 Mon Sep 17 00:00:00 2001 From: Hannah C <70699831+HannahCordes@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:08:44 +0200 Subject: [PATCH] Update script.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test-Code Front-end für die Verbindung von Front- & Back-end --- PV_Calculate_230822/script.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/PV_Calculate_230822/script.js b/PV_Calculate_230822/script.js index 70bed16..d993594 100644 --- a/PV_Calculate_230822/script.js +++ b/PV_Calculate_230822/script.js @@ -30,4 +30,36 @@ function convertAddress() { } }) .catch(error => console.error("Error converting address:", error)); -} \ No newline at end of file +} + + +// test für front-end code für die verbindung von front-end und back-end + +document.getElementById("calculateButton").addEventListener("click", () => { + const selectedInclinationButton = document.querySelector(".toggle-button.active"); + const selectedInclination = selectedInclinationButton.getAttribute("data-inclination"); + + const data = { + postalcode: document.getElementById("postalCodeInput").value, + city: document.getElementById("cityInput").value, + street: document.getElementById("streetInput").value, + number: document.getElementById("numberInput").value, + roofinclination: selectedInclination + }; + + fetch('/calculate', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + .then(response => response.json()) + .then(result => { + // Display the calculation result in your front-end + document.getElementById("resultContainer").textContent = `Efficiency: ${result.efficiency * 100}%`; + }) + .catch(error => { + console.error("Error:", error); + }); +});