You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.1 KiB
57 lines
2.1 KiB
2 months ago
|
<!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:3000/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>
|