aws_faktury/static/scripts.js
dzikafoczka ad7f18db04 test
2024-12-22 15:07:39 +01:00

31 lines
1.2 KiB
JavaScript

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:8080/invoice', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
document.getElementById('responseMessage').innerHTML = `
<p>Upload successful!</p>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
})
.catch(error => {
document.getElementById('responseMessage').innerHTML = `
<p>Error during file upload: ${error.message}</p>
`;
});
} else {
alert('Please select file!');
}
});