1、Ajax优化

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.