document.getElementById('uploadForm').addEventListener('submit', function (event) { event.preventDefault(); const fileInput = document.getElementById('file'); const file = fileInput.files[0]; if (file) { const formData = new FormData(); formData.append('file', file); fetch('http://127.0.0.1/invoice', { method: 'POST', body: formData, }) .then(response => response.json()) .then(data => { document.getElementById('responseMessage').innerHTML = `
Upload successful!
${JSON.stringify(data, null, 2)}`; }) .catch(error => { document.getElementById('responseMessage').innerHTML = `
Error during file upload: ${error.message}
`; }); } else { alert('Please select file!'); } });