Зафиксировал мысль, потом вернусь к идее с бэкендом на питоне.

This commit is contained in:
dr_domi
2026-05-02 23:26:53 +03:00
parent d9e05ea8e0
commit c7220c11b0
5 changed files with 33 additions and 21 deletions
+30
View File
@@ -0,0 +1,30 @@
document.getElementById('bmi-form').addEventListener('submit', function(e) {
e.preventDefault();
const height = document.getElementById('height').value;
const weight = document.getElementById('weight').value;
const resultDiv = document.getElementById('result');
fetch('/calculate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ height, weight })
})
.then(response => response.json())
.then(data => {
if (data.error) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#cc0000';
resultDiv.textContent = data.error;
} else {
resultDiv.style.display = 'block';
resultDiv.style.color = '#003366';
resultDiv.textContent = `Ваш BMI: ${data.bmi}`;
}
})
.catch(() => {
resultDiv.style.display = 'block';
resultDiv.textContent = 'Ошибка соединения с сервером.';
resultDiv.style.color = '#cc0000';
});
});