简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>简单教程( www.twle.cn )</title> </head> <body> <h2>内容是对象</h2> <p>内容是对象会转换为 JavaScript 对象</p> <p id="demo"></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myArr = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myArr['sites'][1]['name']; } }; xmlhttp.open("GET", "/r/show/yufei/json/json_demo", true); xmlhttp.send(); </script> <p>查看服务端数据 <a href="/r/show/yufei/json/json_demo" target="_blank">json_demo</a></p> </body> </html>
运行结果: