实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="myDiv"><h2>内容</h2></div>
<button type="button" onclick="loadXMLDoc()">修改</button>
</body>
<script>
function loadXMLDoc()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
document.getElementById("myDiv").innerHTML=xmlhttp.response;
}
xmlhttp.open("POST","http://localhost:8080/admin/index",true);
xmlhttp.send();
}
</script>
</html>
编写controller视图
@Controller
@RequestMapping("admin")
public class Login {
@RequestMapping("login")
public String login( )
{
return"login";
}
@RequestMapping("index")
@ResponseBody
public String index()
{
return "已经改变";
}