注意:一定要在Apache或者nginx环境下打开网页
HTML代码:
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<body>
<div id="demo"></div>
<div id="demo2"></div>
</body>
</html>
js代码:
<script>
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "index.json", true);
xhttp.send();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var json = this.responseText;
var obj = JSON.parse(json);
var i;
var html="";
var html1="";
for (i=0;i<obj.length;i++) {
html =html+'<p>'+obj[i].name+'</p>