从 php 文件获取 JSON
- <!DOCTYPE html>
- <html>
- <body>
- <h1>从服务器上的 PHP 获取 JSON 数据</h1>
- <p id="demo"></p>
- <script>
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- myObj = JSON.parse(this.responseText);
- document.getElementById("demo").innerHTML = myObj.name;
- }
- };
- xmlhttp.open("GET", "/demo/demo_php_json_encode.php", true);
- xmlhttp.send();
- </script>
- </body>
- </html>