代码示例:(标识:json_ajax_array)
<!DOCTYPE html>
<html>
<body>

<h1>使用 XMLHttpRequest 获取 JSON 文件</h1>
<p>编写为 JSON 数组的内容将转换为 JavaScript 数组。</p>
<p id="demo"></p>

<script>
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
  const myArr = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myArr[0];
}
xmlhttp.open("GET", "/static/demo/txt/json_demo_array.txt", true);
xmlhttp.send();
</script>

</body>
</html>
运行结果: