web-hp-eprint-clone/web/assets/index.js

30 lines
884 B
JavaScript
Raw Normal View History

2024-09-29 19:15:37 +02:00
const uploadForm = document.getElementById('uploadForm');
const uploadStatus = document.getElementById('uploadStatus');
const commandOutput = document.getElementById('commandOutput');
uploadForm.addEventListener('submit', async (e) => {
e.preventDefault();
2024-10-31 20:44:19 +01:00
uploadStatus.textContent = 'Uploading and printing...';
2024-09-29 19:15:37 +02:00
commandOutput.textContent = '';
const formData = new FormData(uploadForm);
try {
const response = await fetch('/upload', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.error) {
throw new Error(result.error);
} else {
uploadStatus.textContent = result.message;
commandOutput.textContent = result.output;
}
} catch (error) {
uploadStatus.textContent = `Error: ${error.message}`;
}
});