31 lines
1.2 KiB
JavaScript
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/invoice', {
|
|||
|
method: 'POST',
|
|||
|
body: formData,
|
|||
|
})
|
|||
|
.then(response => response.json())
|
|||
|
.then(data => {
|
|||
|
document.getElementById('responseMessage').innerHTML = `
|
|||
|
<p>Plik zosta<EFBFBD> pomy<EFBFBD>lnie przes<EFBFBD>any!</p>
|
|||
|
<pre>${{JSON.stringify(data, null, 2)}}</pre>
|
|||
|
`;
|
|||
|
})
|
|||
|
.catch(error => {
|
|||
|
document.getElementById('responseMessage').innerHTML = `
|
|||
|
<p>B<EFBFBD><EFBFBD>d podczas przesy<EFBFBD>ania pliku: ${error.message}</p>
|
|||
|
`;
|
|||
|
});
|
|||
|
} else {
|
|||
|
alert('Prosz<73> wybra<72> plik!');
|
|||
|
}
|
|||
|
});
|
|||
|
|