本文基于:
Eclipse下利用Maven创建SpringBoot的Restful风格程序
在Tomcat目录的SpringBoot项目中,将index.jsp文件修改为
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>my rest api</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("greeting?name=wangle");
});
});
</script>
</head>
<body> <div id="div1"><h2>use jQuery AJAX change content</h2></div>
<button>outside content</button> </body>
</html>
其中11行 "greeting?name=wangle" 为rest api的url
结果:
可获取到Rest API传过来的Json数据并在界面上显示