$.ajax({
type:"post",//指定请求类型
url:"some.php",//指定请求地址
data:"name=john&location=103",//指定传递的数据
success:function (msg){
alert("Data Saved:"+msg);
}//成功之后通过msg反馈出来
error:function (err){
console.log(err);
}//错误输出err
})
ajax四步骤
//创建XMLHttpRequest
var xhr=new XMLHttpRequest();
//2.打开和服务器的链接,规定请求的类型,URL以及是否异步处理请求
xhr.open('get','http://baidu.com',true);
//3.监听事件
xhr.onreadystatechange=function(){
if(xhr.readyState===4&&xhr.status===200){
console.log(xhr.responseText);
}
}
//4.请求发送到服务器
xhr.send();
//post时send需要传参例
xhr.send("uname="+un+"&password"+up);