form.addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(form);
fetch('serv.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: formData
})
.then(response => response.json())
.then(json => {
console.log('data received:');
console.log(`${json}`);
});
});
Выдает ошибку: localhost/:1 Uncaught (in promise) SyntaxError: Unexpected token a in JSON at position 0
Вот форма:
<form class="form" id="formElem">
<input type="text" name="name" required placeholder="Name">
<input type="phone" name="phone" required placeholder="Phone">
<input type="email" name="email" required placeholder="E-mail">
<textarea class="comm" type="text" required name="comment" placeholder="Comment..."></textarea>
<button type="submit">Отправить</button>
</form>