Files
aitsc/debug_frontend.html

56 lines
2.1 KiB
HTML
Raw Permalink Normal View History

2025-10-10 23:39:54 +08:00
<!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>
<div id="results"></div>
<script>
async function testAPI() {
const resultsDiv = document.getElementById('results');
try {
resultsDiv.innerHTML += '<p>🔄 开始测试API调用...</p>';
const response = await fetch('/api/optimization-history', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
});
resultsDiv.innerHTML += `<p>📡 API响应状态: ${response.status}</p>`;
if (response.ok) {
const result = await response.json();
resultsDiv.innerHTML += `<p>✅ API调用成功</p>`;
resultsDiv.innerHTML += `<p>📊 数据格式: ${result.success ? '正确' : '错误'}</p>`;
if (result.success && result.data && result.data.history) {
resultsDiv.innerHTML += `<p>📝 历史记录数量: ${result.data.history.length}</p>`;
// 显示前3条记录
result.data.history.slice(0, 3).forEach((record, index) => {
resultsDiv.innerHTML += `<p>记录 ${index + 1}: ${record.original_text.substring(0, 30)}...</p>`;
});
}
} else {
resultsDiv.innerHTML += `<p>❌ API调用失败: ${response.status}</p>`;
}
} catch (error) {
resultsDiv.innerHTML += `<p>❌ 请求异常: ${error.message}</p>`;
}
}
// 页面加载后执行测试
document.addEventListener('DOMContentLoaded', testAPI);
</script>
</body>
</html>