码迷,mamicode.com
首页 > Web开发 > 详细

ajax封装

时间:2018-10-12 13:49:20      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:sha   llb   settime   pre   弹出层   value   log   time   offset   

ajax: {
//返回弹出层信息
showloading:function prg_show_load_layer(msg,timeout) {
return $.layer.msg(msg,{icon:16,shade:[0.5,‘#f5f5f5‘],scrollbar:false,offset:‘auto‘,time:timeout})
},
closeloading:function prg_close_load_layer(index) {
$.layer.close(index);
},
successMes: function pre_show_tip_layer(){
$.layer.msg("处理完成",{time:300,offset:‘auto‘});
},
get: function (url, param, doFn) {
var options = {};
var exp = new Date();
exp.setTime(exp.getTime() + 40 * 60 * 1000);
options.expires = exp;
var token = gg.core.cookie.getValue("token");
gg.core.cookie.setValue("token",token ,options);
$.ajax({
type: ‘GET‘,
url: url,
data: param,
dataType: "json",
success: function (result) {
if (result.code == 200) {
if (doFn) doFn(result);
}
else if (result.code == 998) {
$.layer.alert(‘用户登录超时,请重新登录!‘, {
icon: 2,
closeBtn: 0
}, function () {
window.location = "login.html";
});
return;
}
else {
$.layer.alert(result.errMsg, {
icon: 2,
closeBtn: 0
});
return;
}
},
error: function () {
$.layer.msg("加载失败",{time:1000,offset:‘auto‘});
},
headers:{
authKey: gg.core.cookie.getValue("token"),
sessionId:gg.core.cookie.getValue("sessionId")
},
});
}
,
post: function (url, param, doFn) {
var options = {};
var exp = new Date();
exp.setTime(exp.getTime() + 40 * 60 * 1000);
options.expires = exp;
gg.core.cookie.setValue("token", gg.core.cookie.getValue("token"),options);
$.ajax({
type: ‘POST‘,
url: url,
data: param,
headers:{
authKey: gg.core.cookie.getValue("token"),
sessionId:gg.core.cookie.getValue("sessionId")
},
dataType: "json",
contentType: "application/json",
success: function (result) {
if (result.code == 200) {
if (doFn) doFn(result);
}
else if (result.code == 998) {
gg.core.cookie.deleteCookid("token")
$.layer.alert(‘用户登录超时,请重新登录!‘, {
icon: 2,
closeBtn: 0
}, function () {
window.location = "login.html";
});
return;
}
else {
$.layer.alert(result.errMsg, {
icon: 2,
closeBtn: 0
});
return;
}
},
error:function(event){
$.layer.msg("加载失败",{time:1000,offset:‘auto‘});
}
});
}
}

ajax封装

标签:sha   llb   settime   pre   弹出层   value   log   time   offset   

原文地址:https://www.cnblogs.com/tuhazi/p/9777271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!