//创建xhr对象
var xhr=new XMLHttpRequest();
//监听请求
xhr.onreadystatechange=function(){
if(xhr.readyState!==4){
console.log(xhr.readyState);
return;
}
if(xhr.status>=200&&xhr.status<=300){
var rep=JSON.parse(xhr.responseText);
if(rep.result){
alert("登录成功");
}else{
alert("登陆失败");
}
}else{
console.log("请求失败");
}
}
//打开这个对象
xhr.open("POST","ajax.php",true);
//设定请求头,指明body中的数据是什么格式
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//发送请求
xhr.send('user=lili&password=123');
ajax_post
最新推荐文章于 2022-03-22 18:14:21 发布