Send a form with AJAX (no reload)

FormData collects every field of the form, files included.

AJAX · Send a form with AJAX (no reload)Intermediate
const form = document.querySelector('#contact');

form.addEventListener('submit', async (e) => {
  e.preventDefault();
  const res  = await fetch(form.action, { method: 'POST', body: new FormData(form) });
  const data = await res.json();
  alert(data.message);
});
fetchformpost