ajax封装

//提交服务器请求
//返回json格式
//1,提交给类 options.type 方法 options.method 处理
//2,并返回 AjaxResult(这也是一个类)类型的的序列化好的字符串
LG.ajax = function(options) {
var p = options || {};
var ashxUrl = options.ashxUrl || "../../../WebHandler/AJAX.ashx?";
var url = p.url || ashxUrl + $.param({ type: p.type, method: p.method, Instance: p.Instance });
$.ajax({
cache: false,
async: typeof(p.async) == "undefined" ? true : p.async,
url: url,
data: p.data,
dataType: 'json', type: 'post',
beforeSend: function() {
LG.loading = true;
if (p.beforeSend)
p.beforeSend();
else
LG.showLoading(p.loading);
},
complete: function() {
LG.loading = false;
if (p.complete)
p.complete();
else
LG.hideLoading();
},
success: function(result) {
if (!result) return;
if (!result.IsError) {
if (p.success)
p.success(result.Data, result.Message);
}
else {
if (p.error) {
//TODO by:DaiDw20170103 处理Session过期进入登录页
if (result.Data == "SessionNoExist") {
alert("用户信息已过期,请重新登录!");
window.top.location = "http://" + window.location.host + "/Login.aspx";
} else {
p.error(result.Message);
}

}
}
},
error: function(result, b) {
LG.tip('发现系统错误 <BR>错误码:' + result.status);
}
});
};

原文地址:https://www.cnblogs.com/daimaxuejia/p/12486053.html