1、Ajax优化

Former-commit-id: 6cc18a6817d40b5838eb18d458fe616cd41ad7f0
master
王兵 5 years ago
parent a9500e31b1
commit 764e28d1e7

@ -154,11 +154,11 @@
return Promise.resolve(rsp);
})
};
function Ajax(module, target, method) {
function Ajax(module, target, method, data) {
this.mModule = module;
this.mTarget = target;
this.mMethod = method;
this.mData = {};
this.mData = data ? data : {};
this.module = function (module) {
this.mModule = module;
@ -177,10 +177,26 @@
return this;
};
this.post = function (callback) {
jsonRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData),
}).then(callback)
switch (this.mMethod) {
case "upload":
case "imports":
return upRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: this.mData
}).then(callback);
break;
case "template":
return downRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData)
}).then(callback);
break;
default:
jsonRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData)
}).then(callback);
}
};
this.create = function (callback) {
this.mMethod = "create";
@ -210,21 +226,28 @@
this.mMethod = "template";
return downRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData),
data: JSON.stringify(this.mData)
}).then(callback)
};
this.imports = function (callback) {
this.mMethod = "imports";
return upRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: this.mData,
data: this.mData
}).then(callback)
};
this.exports = function (callback) {
this.mMethod = "exports";
return downRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData),
data: JSON.stringify(this.mData)
}).then(callback)
};
this.upload = function (callback) {
this.mMethod = "upload";
return upRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: this.mData
}).then(callback)
};
}

Loading…
Cancel
Save

Powered by TurnKey Linux.