ajax标准用法

$.ajax

1
2
3
4
5
6
7
8
9
10
11
12
$.ajax({
type: "POST",
url: "/",
dataType: "json",
data: {},
success: function(data) {

},
error: function(XMLHttpRequest, textStatus, errorThrown) {

}
})

详细写法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$.ajax({
url:"/", //请求的url地址
dataType:"json", //返回格式为json
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
data:{"id":"value"}, //参数值
type:"POST", //请求方式
beforeSend:function(){
//请求前的处理
},
success:function(req){
//请求成功时处理
},
complete:function(){
//请求完成的处理
},
error:function(){
//请求出错处理
}
});

$.post

1
2
3
4
5
$.post(`/xx`,{

},(data)=>{

});