progodyssey/public/index.js

25 lines
712 B
JavaScript
Raw Normal View History

2024-08-31 13:06:03 +00:00
document.getElementById('applicationForm').addEventListener('submit', function(event) {
event.preventDefault();
2024-08-31 13:06:03 +00:00
// Get form data
const formData = new FormData(this);
const data = Object.fromEntries(formData.entries());
// Send form data to server-side endpoint
fetch('/submit', {
2024-08-31 13:06:03 +00:00
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(result => {
console.log('Success:', result);
document.body.innerHTML = '<h2>Thank you for your application!</h2>';
2024-08-31 13:06:03 +00:00
})
.catch(error => {
console.error('Error:', error);
});
});