从 php 文件获取 JSON 数组
- <!DOCTYPE html>
- <html>
- <body>
- <h1>从 PHP 文件获取 JSON 数据,并把它转换为 JavaScript 数组</h1>
- <p id="demo"></p>
- <script>
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- var myObj = JSON.parse(this.responseText);
- document.getElementById("demo").innerHTML = myObj[2];
- }
- };
- xmlhttp.open("GET", "/demo/demo_php_json_encode_array.php", true);
- xmlhttp.send();
- </script>
- </body>
- </html>