?//
ec.api = function (controller) {
this.api_base = L.route + "/api/" + controller + "/";
this.ajax = function (_url, _type, _data, _success, _error, mask) {
if (mask) ke.mask();
$.ajax({
dataType: "json",
xhrFields: { withCredentials: true },
crossDomain: true,
contentType: "application/json",
cache: false,
type: _type,
url: _url,
data: _data,
async: true,
success: _success,
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (mask)
ke.unMask();
ec.api.error(XMLHttpRequest, textStatus, _error);
},
complete: function (XMLHttpRequest, status) {
if (mask)
ke.unMask();
if (status == 'timeout') {
ajaxTimeoutTest.abort();
$.messager.confirm(L.G("pȝ错误"), L.G("抱歉,操作已超?), null, "error");
}
}
});
}
//调用接口Q_type,_callback 参数可省
this.excute = function (fun, data, _type, _callback) {
if (data == null) data = "";
var type = "get";
if (ke.isString(_type)) type = _type;
var url = this.api_base + fun;
this.ajax(url, _type, data, _callback);
}
this.get = function (fun, callback, mask) {
this.ajax(this.api_base + fun, "get", null, callback, null, mask);
}
this.put = function (fun, data, callback, mask) {
if (data) {
if ($.isFunction(data)) {
callback = data;
data = "";
}
else
data = JSON.stringify(data);
}
this.ajax(this.api_base + fun, "put", data, callback, null, mask);
}
this.post = function (fun, data, callback, mask) {
if (data) {
if ($.isFunction(data)) {
callback = data;
data = "";
}
else
data = JSON.stringify(data);
}
this.ajax(this.api_base + fun, "post", data, callback, null, mask);
}
}
ec.api.error = function (req, textStatus) {
try {
var r = JSON.parse(req.responseText);
if (r.code == 1000 || r.code == -1 || r.code == 0)
window.top.ec.notify(r.msg, "error", 3000);
else if (r.code = 1001)
window.top.location.href = L.route + "/account/login"
else
alert(req.responseText);
}
catch (e) {
alert(req.responseText);
}
if (ec.api.errorEnd)
ec.api.errorEnd();
}
精品国产午夜理论片不卡_亚洲欧美人高清精品a∨_丰满人妻一区二区三区视频_奇米影视7777久久