- Prepare jquery.min.js file and store it in js file under webapp
- Since the configured front controller intercepts all requests, it is necessary to let the front controller release the static resources, so add in spring-mvc.xml:
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
3. If you need to transfer the data of the page to the server and encapsulate it in the manner of javabean, as a parameter, you need to import dependencies: 4. At this point, you can fill in the code in html. First import the imported jquery.min.js file, and secondly edit the code, for example:
$(function () {
$("#btn").click(function (){
$.ajax({
//编写json格式数据
url: "controller3/testAjax",
contentType: "application/json;charset=UTF-8",
data:'{"uname":"huang","age":30}',
dataType: "json",
type: "post",
success: function (data) {
//data服务器端响应的json数据,进行解析
alert(data);
alert(data.uname);
alert(data.age);
}
})
});
});
5. Complete the background service, you can