-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.js
59 lines (58 loc) · 1.26 KB
/
resource.js
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
(function($, g) {
var config = {
contextpath : "http://localhost:8004",
};
var http = {
config : config,
post : function(url, data, config) {
$.extend(config, {
type : "POST"
});
return ajax(url, data, config);
},
get : function(url, data, config) {
$.extend(config, {
type : "GET"
});
return ajax(url, data, config);
},
hooks : {
beforeSend : function() {
},
afterSend : function() {
},
processData : function(result, resolve, reject) {
resolve(result);
}
}
};
var defaults = {
async : true,
type : "POST",
datatype : "json",
contentType : "application/json",
timeout : 30000,
beforeSend : function() {
http.hooks.beforeSend.call(this);
},
success : function(result, status, xhr) {
http.hooks.processData.call(this, result, dtd.resolve, dtd.reject);
},
error : function(result, error) {
throw result.statusText;
},
complete : function(req, status) {
http.hooks.afterSend(this);
}
};
function ajax(url, postData, config) {
var dtd = $.Deferred(), data, options = {
url : config.contextpath + url,
data : JSON.stringify(postData)
};
options = $.extend({}, defaults, options, config);
$.ajax(options);
return dtd.promise();
}
g.$http = http;
})(jQuery, this);