document.addEventListener('DOMContentLoaded', () => {
document.querySelector('form').addEventListener('submit', async (event) => {
event.preventDefault();
const { currentTarget: form } = event;
const { method, action } = form;
const response = await fetch(action, { method, body: new FormData(form) });
const json = await response.json();
if (json.url) {
window.location.href = '/' + json.url;
} else {
alert(json.status + ' - ' + json.message);
}
})
})
|