web_avt / online.html
DmitrMakeev's picture
Update online.html
8da0ed2 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Image</title>
</head>
<body>
<h1>Upload Image</h1>
<form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
<input type="file" name="photo">
<button type="submit">Upload</button>
</form>
<div id="message"></div>
<script>
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault();
var formData = new FormData(this);
fetch('/upload', {
method: 'POST',
body: formData
})
.then(response => {
if (response.ok) {
return response.text();
}
throw new Error('Network response was not ok.');
})
.then(data => {
document.getElementById('message').innerText = data;
})
.catch(error => {
document.getElementById('message').innerText = 'Error: ' + error.message;
});
});
</script>
</body>
</html>