Untitled
unknown
plain_text
2 years ago
1.2 kB
5
Indexable
<script>
document.getElementById('loginForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
// Get form data
const formData = new FormData(this);
// Convert form data to JSON
const jsonData = {};
formData.forEach((value, key) => {
jsonData[key] = value;
});
// Send form data to Node.js server
fetch('/submit-form', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Response from server:', data);
})
.catch(error => {
console.error('Error:', error);
});
});
</script>Editor is loading...
Leave a Comment