用jQuery Ajax实现前端调用SpringBoot Rest风格API

本文基于:

Eclipse下利用Maven创建SpringBoot的Restful风格程序

SpringBoot发布到独立的tomcat中运行

 

在Tomcat目录的SpringBoot项目中,将index.jsp文件修改为

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>my rest api</title>
 6 <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
 7 </script>
 8 <script>
 9 $(document).ready(function(){
10     $("button").click(function(){
11         $("#div1").load("greeting?name=wangle");
12     });
13 });
14 </script>
15 </head>
16 <body>
17 
18 <div id="div1"><h2>use jQuery AJAX change content</h2></div>
19 <button>outside content</button>
20 
21 </body>
22 </html>

其中11行 "greeting?name=wangle" 为rest api的url

 

结果:

可获取到Rest API传过来的Json数据并在界面上显示

 

转载于:https://www.cnblogs.com/zhile/p/8253602.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值