let xhr = new XMLHttpRequest(); //创建Ajax核心对象 xhr.open('methods','url'); //建立请求连接 xhr.send(null); //发送请求 // get请求查询字符串用?拼接在url后边 send为null // post请求添加: // xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded') xhr.onreadystatechange = () => { //创建监听事件 if(xhr.readyState == 4 && xhr.status == 200){ //reareadyState==4:请求成功;status==200:响应成功 xhr.responseText //服务器响应的数据 } } console.log(xhr)