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); + }); +});