parent
90d77c4a66
commit
540df09fba
@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>信息导入页面</title>
|
||||
<link rel="stylesheet" href="style_1.css">
|
||||
|
||||
</head>
|
||||
|
||||
<body class="background-container">
|
||||
<div class="firstcontainer">
|
||||
<div class="text">请导入学生名单:<span class="intext" id="filePrompt">点击此处导入文件</span></div>
|
||||
<input type="file" id="fileInput" accept=".xlsx, .xls" style="display:none;">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('filePrompt').addEventListener('click', function () {
|
||||
document.getElementById('fileInput').click();
|
||||
});
|
||||
|
||||
document.getElementById('fileInput').addEventListener('change', async function (event) {
|
||||
var file = event.target.files[0];
|
||||
if (file) {
|
||||
// Optional: Validate file type
|
||||
if (!file.type.match(/application\/vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|application\/vnd\.ms-excel/)) {
|
||||
alert('请上传有效的 Excel 文件。');
|
||||
return;
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
try {
|
||||
const response = await fetch('http://localhost:3001/upload', { // Adjust URL if necessary
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok: ' + response.statusText);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log('服务器响应:', result);
|
||||
alert(result.message);
|
||||
} catch (error) {
|
||||
console.error('文件上传失败:', error);
|
||||
alert('文件上传失败,请重试。错误信息:' + error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in new issue