form
function submitForm() {
var formData = new FormData(document.getElementById("myForm"));
fetch('/path-to-your-server-side-script', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
console.log(data); // Optionally handle the response
// You can also show a success message or redirect the user after successful submission
})
.catch(error => {
console.error('There was a problem with your fetch operation:', error);
// Handle error
});
}
Comments
Post a Comment