<script>
//第一步创建xmlhttprequest
var xmlhttp;
if (window.XMLHttpRequest) {//code for ie7+ firefox,chrome,opera,safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}//第二步发送请求
//xmlhttp.open("GET", "http://47.92.82.13:4000/showMessage", true);
xmlhttp.open("GET", "./data/data.json", true);//true false//判断是否是异步
xmlhttp.send();
//第三回回调函数
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(JSON.parse(xmlhttp.responseText));
}
}
/*let obj={
a:"abc",
}
console.log(obj);
let str=JSON.stringify(obj);//将对象转为字符串的形式存储
console.log(str);
console.log(JSON.parse(str));//将字符串转换为对象的存储形式*/
</script>