-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (22 loc) · 1013 Bytes
/
script.js
File metadata and controls
25 lines (22 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
document.getElementById('upload-form').addEventListener('submit', async function(event) {
event.preventDefault(); // Prevent the default form submission
const formData = new FormData(this); // Create a FormData object from the form
try {
const response = await fetch('/', {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.success) {
// Show the result image
document.getElementById('results-message').textContent = 'Results:';
const resultImage = document.getElementById('result-image');
resultImage.src = data.image_url; // Set the image source to the returned URL
resultImage.style.display = 'block'; // Show the image
} else {
alert(data.error || 'An unknown error occurred while processing the files.');
}
} catch (error) {
alert('An error occurred while submitting the form: ' + error.message);
}
});