document.getElementById('myForm').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
const jsonObject = {};
formData.forEach(function(value, key) {
jsonObject[key] = value;
});
fetch('your-php-script.php', {
method: 'POST',
body: JSON.stringify(jsonObject),
headers: {
'Content-Type': 'application/json'
}
})
.then(function(response) {
return response.json();
})
.then(function(data) {
console.log(data);
})
.catch(function(error) {
console.error('Error:', error);
});
});