Ajax异步加载数据
我们再创建一个pojo类:User
编写controller(编写一个集合,展示到前端页面):
编写test2.jsp(前端页面):
<%--
Created by IntelliJ IDEA.
User: admin
Date: 2022/5/22
Time: 8:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
<script src="${pageContext.request.contextPath}/statics/js/jquery-3.6.0.js"></script>
<script>
$(function () {
$("#btn").click(function () {
/*
$.post(url,param[可以省略],success)
*/
$.post("${pageContext.request.contextPath}/a2",function (data) {
let html="";
for (let i = 0; ihtml +=" "+ "
""+data[i].name+" "+
""+data[i].age+" "+
""+data[i].sex+" "+
"
}
$("#content").html(html);
})
})
});
</script>
姓名
年龄
性别
<%-- 数据,后台--%>
测试: