ajax

120 阅读1分钟
 let xhr=new XMLHttpRequest();//创建ajax实例
 xhr.open('get','./data.json',false)//确定请求路径
 xhr.onreadystatechange = function(){//监听请求状态
     if(xhr.readyState == 4 && xhr.status= 200){
         JSON.parse(xhr.response)
     }
 }
 xhr.send();发生请求
     // JSON.parse   把JSON字符串 转成  JSON对象
    // JSON.stringify 把对象 转成 JSON字符串