//第一步,创建异步XMLHttpRequest对象
let xmlhttp = new XMLHTTPrequest();
//第五步,注册回调函数
xmlhttp.onreadystatechange = callback
//第二步,配置请求信息
xmlhttp.open("GET", "backend/api",false); // 这里同步, 第三参数不写则为true(异步)
//第三步, post请求下需要配置请求头信息
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//第四步,发送请求
xmlhttp.send(null);
//如果是post请求
//xmlHttp.send("methodName = GetAllComment&str1=str1&str2=str2");
//被执行回调函数
function callback() {
if(xmlhttp.readyState == 200){
if(xmlhttp.status == 4){
console.log(xmlhttp.responseText);
} }
}