<!DOCTYPE html> <html> <body> <h1>使用 XMLHttpRequest 获取 JSON 文件</h1> <p id="demo"></p> <script> const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { const myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.name; } xmlhttp.open("GET", "/static/demo/txt/json.txt"); xmlhttp.send(); </script> </body> </html>