var xhr = new XMLHttpRequest();
// xhr.open("get","http://localhost:3000/students",true);
// xhr.send();
data = {
"name":"action is power"
};
xhr.open("post","http://localhost:3000/students",true);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(JSON.stringify(data));
xhr.onreadystatechange = function(){
let {status,readyState} = xhr;
if(readyState==4){
if(200<=status && 300>status){
console.log(xhr.responseText);
}
}
}
}
ajax 请求get 非常简单
post 请求,需要设置 设置下