DmitrMakeev commited on
Commit
8da0ed2
1 Parent(s): 3536506

Update online.html

Browse files
Files changed (1) hide show
  1. online.html +37 -13
online.html CHANGED
@@ -1,14 +1,38 @@
1
  <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Загрузка файла</title>
6
- </head>
7
- <body>
8
- <h1>Upload Image</h1>
9
- <form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
10
- <input type="file" name="photo">
11
- <button type="submit">Upload</button>
12
- </form>
13
- </body>
14
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Upload Image</title>
7
+ </head>
8
+ <body>
9
+ <h1>Upload Image</h1>
10
+ <form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
11
+ <input type="file" name="photo">
12
+ <button type="submit">Upload</button>
13
+ </form>
14
+ <div id="message"></div>
15
+ <script>
16
+ document.getElementById('uploadForm').addEventListener('submit', function(event) {
17
+ event.preventDefault();
18
+ var formData = new FormData(this);
19
+ fetch('/upload', {
20
+ method: 'POST',
21
+ body: formData
22
+ })
23
+ .then(response => {
24
+ if (response.ok) {
25
+ return response.text();
26
+ }
27
+ throw new Error('Network response was not ok.');
28
+ })
29
+ .then(data => {
30
+ document.getElementById('message').innerText = data;
31
+ })
32
+ .catch(error => {
33
+ document.getElementById('message').innerText = 'Error: ' + error.message;
34
+ });
35
+ });
36
+ </script>
37
+ </body>
38
+ </html>