T
T
TonyHabr022022-02-08 13:42:18
AJAX
TonyHabr02, 2022-02-08 13:42:18

The form on the site is not being sent, what could be the error?

The form is not sent, it gives an error in this section of the code. Help)

const form = document.getElementById('form-contacts');
form.addEventListener('submit', formSend);

async function formSend(e) {
        e.preventDefault();

        let error = formValidate(form);

        let formData = new FormData(form);

        if (error === 0) {
            let response = await fetch('sendmail.php', {
                method: 'POST',
                body: formData
            });
            if (response.ok) {
                let result = await response.json();
                succesModal.classList.add('active');
                alert(result.message);
                formPreview.innerHTML = '';
                form.reset();
            } else {
                alert("Что-то пошло не так. Пожалуйста, повторите попытку.");
            }
        } else {
            editModal.classList.add('active');
        }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question