$('#save').on('click',function(){
//定义http请求
var request = new XMLHttpRequest();
request.open('post','test.php',true);
//获取数据
var data={
username:$('#user').val(),
password:$('#pass').val()
}
data = $.param(data);
//设置响应头
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
request.send(data);
//监听
request.onreadystatechange=function(){
if(request.readyState===4){ //表示完成
if (request.status===200) { //表示请求成功
//成功之后做的事情
console.log('成功',request.responseText);
} else {
//表示失败
console.log("发生错误:", request.status);
}
}
}
})