本站开始提供一些免费有意思的API让大伙来使用. 所有的API都是在这台主机VPS上实现和运行的.
举这个API为例 fortune 能随机的返回一段(句)话 然后我们就可以通过 Javascript/JQuery/Ajax 来动态的显示在浏览器中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <script type='text/Javascript' src='https://helloacm.com/jquery/jquery-2.1.4.min.js'></script> <script type='text/Javascript'> $(document).ready(function () { $.ajax( { dataType: "json", url: "https://helloacm.com/api/fortune/", cache: false, success: function (response) { document.write(response); } }) }); </script> |
<script type='text/Javascript' src='https://helloacm.com/jquery/jquery-2.1.4.min.js'></script> <script type='text/Javascript'> $(document).ready(function () { $.ajax( { dataType: "json", url: "https://helloacm.com/api/fortune/", cache: false, success: function (response) { document.write(response); } }) }); </script>
做少量修改加个显示 区域 和按钮
<div id='fortune_text'> </div>
并把 document.write 改成 $(‘#fortune_text’).html(response).
JQUERY 方便的调用AJAX并把获得的结果 按 JSON格式解码 要写的代码实际很少了.
英文: https://helloacm.com/how-to-invoke-apis-the-javascriptajax-example/
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK