Background Code
Package controller;
Import Javax.servlet.http.HttpServletRequest;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.bind.annotation.ResponseBody;
@Controller public
class Ajaxhandler {
@RequestMapping (value = "/ajax.action", method = Requestmethod.post, produces = "Text/html;charset=utf-8")
@ResponseBody public
String method1 (HttpServletRequest request) {
//Get the value
of key username String username = request.getparameter ("username");
Processing the obtained parameter
System.out.println (username);
String reslut = "Login succeeded:" + username;
Return the result return
Reslut;}
}
Front Code
<script type= "Text/javascript" src= "js/jquery-3.2.1.min.js" ></script>
<script type= "text/ JavaScript >
$ (function () {/
* Ajax Post */
$ (' #submitbt '). Click (function () {
var Username = $ ("# Username "). Val ();
$.post ("Ajax.action", {
username:username,
}, function (data) {
//from the back of the database
;
});
} );
/* Ajax post */
});
</script>
<body>
<form action= "" method= "post" >
username<input type= "text" Name= "username" id= "username"/>
<input type= "button" value= "Ajax" id= "SUBMITBT" >
</form>
</body>