访问node后端接口示例(入门)

一、基础安装参考我的另一篇随笔

https://www.cnblogs.com/xiaojiangk/p/13753062.html

另在之前的基础上引入了jquery,方便使用ajax

 

二、前端代码

1.home.html

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>node home</title> 5 </head> 6 <body> 7 <div id="wrap">home</div> 8 <button onclick="window.location.href = '/city.html'">go to city</button> 9 <script type="text/javascript" src="./static/jquery/jquery.min.js"></script> 10 <script type="text/javascript"> 11 window.onload = function () { 12 var wrap = $('#wrap') 13 14 $.ajax({ 15 url: '/', 16 type: 'GET', 17 success: function (res) { 18 if (res.errno == 0) { 19 res = res.data 20 console.log(res) 21 } 22 }, 23 error: function (msg) { 24 console.log(msg) 25 } 26 }) 27 } 28 </script> 29 </body> 30 </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wppzyz.html