bigly-chat/static/main.js
2024-09-07 18:12:58 -04:00

24 lines
No EOL
531 B
JavaScript

async function formClick(ev) {
ev.preventDefault();
let { target } = ev;
let fetched = await fetch(target.action, {
'method': 'POST',
'body': new FormData(target)
});
let json = await fetched.json();
document.querySelector('.form-message').textContent = json.message;
if (json.redirect) {
setTimeout(function () {
window.location.href = json.redirect;
}, 2000);
}
}
window.onload = function () {
document.addEventListener('submit', formClick);
}