使用工具:idea
使用框架:spring boot+thymeleaf+jsp
报错:
GET http://localhost:8080/static/jquery-3.5.1.js net::ERR_ABORTED 404
现象:
jsp代码:
<html>
<head>
<title>Ajax测试</title>
</head>
<body>
<input type="button" id="btn" value="获取数据">
<table width="40%" align="center">
<tr>
<td>姓名</td>
<td>年龄</td>
<td>住址</td>
<td>月收入</td>
<td>删除</td>
</tr>
<tbody id="context">
</tbody>
</table>
<script type="text/javascript" src="/static/jquery-3.5.1.js"></script>
<script>
$(function () {
$("#btn").click(function () {
$.ajax({
url:"user/findUser",
type:"POST",
success:function (data) {
var html ='';
for (let i = 0; i <data.length ; i++) {
html+="<tr>"+
"<td>"+data[i].userName+"</td>"+
"<td>"+data[i].realAge+"</td>"+
"<td>"+data[i].address+"</td>"+
"<td>"+data[i].mouthIncome+"</td>"+
"<td>"+data[i].delFlag+"</td>"+
"</tr>"
}
$("#context").html(html)
}
})
})
})
</script>
</body>
</html>
报错原因: 现在查找js库都是直接从static中查找,直接将static去掉就行了
<script type="text/javascript" src="jquery-3.5.1.js"></script>
结果: