-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (25 loc) · 872 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
document.addEventListener('DOMContentLoaded', () => {
const ajaxSend = async (formData) => {
const fetchResp = await fetch('mail.php', {
method: 'POST',
body: formData
});
if (!fetchResp.ok) {
throw new Error(`Ошибка по адресу ${url}, статус ошибки ${fetchResp.status}`);
}
return await fetchResp.text();
};
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function (e) {
e.preventDefault();
const formData = new FormData(this);
ajaxSend(formData)
.then((response) => {
console.log(response);
form.reset(); // очищаем поля формы
})
.catch((err) => console.error(err))
});
});
});