calc_run('beton');
document.addEventListener('DOMContentLoaded', function(){
document.getElementById('beton-calculyator').submit();
});
function calc_run(calc_name) {
let form = document.getElementById(calc_name + '-calculyator');
let answer = document.getElementById(calc_name + '-answer');
form.addEventListener('submit', function(ev) {
ev.preventDefault();
let formData = new FormData(this);
let promise = fetch('/answer/' + calc_name + '.php',
{
method: 'POST',
body: formData,
});
promise.then(
response => {
return response.text();
}
).then(
text => {
answer.innerHTML = text;
}
);
});
}
Страница постоянно перезагружается. Почему?