<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。