Untitled
unknown
plain_text
a year ago
1.2 kB
4
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