当前阅读教程:JSON教程 > 从服务端接收数组的 JSON 数据 | |
阅读(22555525) 收藏 赞(5685) 分享 | |
上一篇: 从服务端接收 JSON 数据 | 下一篇: JSON.stringify()转字符串 |
json_demo_array.txt [ "Google", "Runoob", "Taobao" ] 完整实例代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS中文教程网 8939.org</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[1]; } }; xmlhttp.open("GET", "http://www.8939.org/json/json_demo_array.txt", true); xmlhttp.send();
</script>
<p>查看服务端数据 <a href="http://www.8939.org/json/json_demo_array.txt" target="_blank">json_demo_array.txt</a></p>
</body> </html> |
|
上一篇: 从服务端接收 JSON 数据 | 下一篇: JSON.stringify()转字符串 |