前后端分离
@ Zhang zhiyang · Monday, Jan 1, 0001 · 1 minute read · Update at Monday, Jan 1, 0001

基础的前后端分离

前后端分离

前端HTML页面通过AJAX调用后端的RESTFUL API接口并使用JSON数据进行交互

0x00 原生ajax

前端

<html>
<head>
<script type="text/javascript">
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","json.php",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
</script>
</head>
<body>
<div id="myDiv"></div>
</body>
</html>

后端

<?php
  $arr = ['a'=>'1' , 'b'=>'2'];
  echo json_encode($arr);
php
Save as image
Zhang zhiyang's blog
不过是些许风霜罢了
c cyber http linux math mysql php python 前端

© 2016 - 2022 Zhangzhiyang的博客

Powered by Hugo with theme Dream.

我听别人说这世界上有一种鸟是没有脚的,它只能够一直的飞呀飞呀,飞累了就在风里面睡觉,这种鸟一辈子只能下地一次,那一次就是它死亡的时候。

日程

Zhangzhiyang的 ❤️ 博客

其他

如果你喜欢我的开源项目或者它们可以给你带来帮助,可以赏一杯咖啡 ☕ 给我。~

If you like my open source projects or they can help you. You can buy me a coffee ☕.~

PayPal

https://paypal.me/g1eny0ung

Patreon

Become a Patron!

微信赞赏码

wechat

最好附加一下信息或者留言,方便我可以将捐助记录 📝 下来,十分感谢 🙏。

It is better to attach some information or leave a message so that I can record the donation 📝, thank you very much 🙏.