用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數據並在界面上顯示

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM