WACATW commited on
Commit
7fb3b78
·
verified ·
1 Parent(s): 22d883f

Update static/js/app.js

Browse files
Files changed (1) hide show
  1. static/js/app.js +15 -16
static/js/app.js CHANGED
@@ -106,27 +106,26 @@ function uploadFiles(files) {
106
  };
107
 
108
  xhr.onload = function() {
109
- if (xhr.status === 200) {
 
 
 
 
110
  uploaded++;
111
  } else {
112
  failed++;
113
- console.error('Upload failed:', xhr.responseText);
114
  }
115
- uploadNext(index + 1);
116
- };
117
-
118
- xhr.onerror = function() {
119
  failed++;
120
- console.error('Upload error');
121
- uploadNext(index + 1);
122
- };
123
-
124
- xhr.open('POST', '/api/upload', true);
125
- xhr.send(formData);
126
- };
127
-
128
- uploadNext(0);
129
- }
130
 
131
  // 👇 新增一个网速格式化辅助函数(放在 uploadFiles 函数下方即可)
132
  function formatSpeed(bytesPerSecond) {
 
106
  };
107
 
108
  xhr.onload = function() {
109
+ // 检查 HTTP 状态码和 JSON 里的 success 字段
110
+ if (xhr.status === 200) {
111
+ try {
112
+ const data = JSON.parse(xhr.responseText);
113
+ if (data.success) {
114
  uploaded++;
115
  } else {
116
  failed++;
117
+ console.error('后端上传失败:', data.error);
118
  }
119
+ } catch (e) {
 
 
 
120
  failed++;
121
+ console.error('解析响应失败:', e);
122
+ }
123
+ } else {
124
+ failed++;
125
+ console.error('上传请求失败, 状态码:', xhr.status);
126
+ }
127
+ uploadNext(index + 1);
128
+ };
 
 
129
 
130
  // 👇 新增一个网速格式化辅助函数(放在 uploadFiles 函数下方即可)
131
  function formatSpeed(bytesPerSecond) {