JSON基础入门实战讲解在线视频课程-JSON.parse() 从服务端接收数组的 JSON 数据

版权声明:黄菊华 https://blog.csdn.net/u013818205/article/details/86626042

从服务端接收数组的 JSON 数据
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基础入门实战讲解在线视频课程
https://edu.csdn.net/course/detail/10088
JSON基础入门实战讲解在线视频课程-JSON.parse() 从服务端接收数组的 JSON 数据

猜你喜欢

转载自blog.csdn.net/u013818205/article/details/86626042
今日推荐