aws_faktury/static/scripts.js

31 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-12-21 22:11:47 +01:00
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);
2024-12-22 15:07:39 +01:00
fetch('http://127.0.0.1:8080/invoice', {
2024-12-21 22:11:47 +01:00
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
document.getElementById('responseMessage').innerHTML = `
2024-12-21 22:13:27 +01:00
<p>Upload successful!</p>
<pre>${JSON.stringify(data, null, 2)}</pre>
2024-12-21 22:11:47 +01:00
`;
})
.catch(error => {
document.getElementById('responseMessage').innerHTML = `
2024-12-21 22:13:27 +01:00
<p>Error during file upload: ${error.message}</p>
2024-12-21 22:11:47 +01:00
`;
});
} else {
2024-12-21 22:13:27 +01:00
alert('Please select file!');
2024-12-21 22:11:47 +01:00
}
});