?jQuery是一个库,里面包含大量的js方法(函数)?
ajax
?1、编写jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
<%--导入静态资源到jsp前端页面--%>
<script src="${pageContext.request.contextPath}/statics/js/jquery-3.6.0.js"></script>
<%--$就代表jquery--%>
<script>
function a() {
$.post({
url:"${pageContext.request.contextPath}/a1",
data:{"name":${"#username"}.val()},
success:function (data) {
alert(data);
},
error:function () {
}
})
}
</script>
</head>
<body>
<%--失去焦点的时候,发起一个请求(携带信息)到后台--%>
用户名<input type="text" id="username" onblur="a()">
</body>
</html>
?2、编写controller
@RequestMapping("/a1")
public void a1(String name, HttpServletResponse response) throws IOException {
System.out.println("a1:param=>" + name);
if ("ming".equals(name)){
response.getWriter().print("true");
}else {
response.getWriter().print("false");
}
}
异步加载数据?
?
做后端,前端需要掌握:
?
?
|