62 lines
2.3 KiB
HTML
62 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>前端调试页面</title>
|
|
</head>
|
|
<body>
|
|
<h1>前端调试页面</h1>
|
|
<button onclick="testAPI()">测试API调用</button>
|
|
<button onclick="testLocalStorage()">测试LocalStorage</button>
|
|
<div id="result"></div>
|
|
|
|
<script>
|
|
function testAPI() {
|
|
console.log('开始测试API...');
|
|
fetch('/api/students/all')
|
|
.then(response => {
|
|
console.log('API响应状态:', response.status);
|
|
if (!response.ok) {
|
|
throw new Error('网络响应错误: ' + response.status);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log('API数据:', data);
|
|
document.getElementById('result').innerHTML =
|
|
'<h3>API测试成功</h3>' +
|
|
'<p>学生数量: ' + data.students.length + '</p>' +
|
|
'<pre>' + JSON.stringify(data, null, 2) + '</pre>';
|
|
})
|
|
.catch(error => {
|
|
console.error('API错误:', error);
|
|
document.getElementById('result').innerHTML =
|
|
'<h3>API测试失败</h3>' +
|
|
'<p>错误: ' + error.message + '</p>';
|
|
});
|
|
}
|
|
|
|
function testLocalStorage() {
|
|
console.log('测试LocalStorage...');
|
|
const username = localStorage.getItem('username');
|
|
const role = localStorage.getItem('role');
|
|
|
|
document.getElementById('result').innerHTML =
|
|
'<h3>LocalStorage测试</h3>' +
|
|
'<p>用户名: ' + (username || '未设置') + '</p>' +
|
|
'<p>角色: ' + (role || '未设置') + '</p>';
|
|
|
|
console.log('LocalStorage - username:', username);
|
|
console.log('LocalStorage - role:', role);
|
|
}
|
|
|
|
// 页面加载时自动测试
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
console.log('调试页面加载完成');
|
|
testLocalStorage();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|