//ajax
function http({ url, type = "post", dataType = "json",
xhrFields = {withCredentials:true},crossDomain=true,data = {}, success,error }) {
$.ajax({
url: url,
type,
dataType,
data,
xhrFields,//携带cookie
crossDomain,//携带cookie
success: function (res) {
success(res);
},
error:function (err) {
error(err)
}
})
}
//调用
var list = {id:2,name:'123'}
http({
url: getPath,
// data:list,
// xhrFields:{},
// crossDomain:'',
success: res => {
console.log(res);
},
error:err => {
console.log(err);
}
});
jq再次封装Ajax
最新推荐文章于 2022-03-08 10:04:14 发布