Зафиксировал мысль, потом вернусь к идее с бэкендом на питоне.
This commit is contained in:
@@ -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';
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user