-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleBase.js
More file actions
116 lines (112 loc) · 4.12 KB
/
Copy pathModuleBase.js
File metadata and controls
116 lines (112 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
define(["jquery","jquerycrsdomain", "../utils/SysConfig"], function ($, jquerycrsdomain,SysConfig) {
var RspData = function () {
this.isSuccess = null;
this.ErrorMsg = null;
this.Data = null;
}
var ModuleBase = function (url, method, data, callback, contentType) {
this.Url = url;
this.Method = method;
this.CallBack = callback;
this.Data=data;
this.ConentType = contentType;
this.module = {};
this.UsingType = false;
if (method == null) {
this.Method = window.SysInfo.Ajax.postMethod;
}
if (typeof contentType !== "undefined") {
this.UsingType = true;
}
}
ModuleBase.prototype = {
Ajax: function () {
var self = this;
var rspdata=new RspData();
if (self.UsingType == false) {
(function () {
$.ajax({
'type': self.Method,
'url': self.Url,
'data': self.Data,
'dataType': 'json',
'success': function (data) {
rspdata.isSuccess = true;
rspdata.Data = data;
self.CallBack.call(this,rspdata);
},
error: function (xhr, ajaxOptions, thrownError) {
rspdata.isSuccess = false;
rspdata.Data = null;
rspdata.ErrorMsg = thrownError;
self.CallBack.call(this,rspdata);
}
});
})();
}
else {
(function () {
var rspdata=new RspData();
$.ajax({
'type': self.Method,
'url': self.Url,
'data': self.Data,
'contentType': self.ConentType,
'dataType': 'json',
'success': function (data) {
rspdata.isSuccess = true;
rspdata.Data = data;
self.CallBack.call(this,rspdata);
},
error: function (xhr, ajaxOptions, thrownError) {
rspdata.isSuccess = false;
rspdata.Data = null;
rspdata.ErrorMsg = thrownError;
self.CallBack.call(this,rspdata);
}
});
})();
}
},
JqChain: function () {
var self = this;
var rspdata=new RspData();
if (self.Method.toLowerCase() == "post") {
return $.post(self.Url, self.Data, self.ConentType).done(function (data) {
rspdata.isSuccess = true;
rspdata.Data = data;
self.CallBack(rspdata);
}).fail(function (jqXHR, textStatus) {
rspdata.isSuccess = false;
rspdata.Data = null;
rspdata.ErrorMsg = textStatus;
self.CallBack(rspdata);
});
}
else {
return $.get(self.Url, self.Data, self.ConentType).done(function (data) {
rspdata.isSuccess = true;
rspdata.Data = data;
self.CallBack(rspdata);
}).fail(function (jqXHR, textStatus) {
rspdata.isSuccess = false;
rspdata.Data = null;
rspdata.ErrorMsg = textStatus;
selft.CallBack(rspdata);
});
}
}
}
//singleton
var instance;
var InstanceBase = {
GetInstance: function () {
if (!instance) {
instance = new ModuleBase();
}
return instance;
},
MBase: ModuleBase,
}
return InstanceBase;
});