-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAjaxHelper.js
More file actions
42 lines (37 loc) · 1.5 KB
/
AjaxHelper.js
File metadata and controls
42 lines (37 loc) · 1.5 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
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
function AjaxHelper() {
this.ajax = function (url, type, dataType, data, callback) {
$.ajax({
url: url,
type: type,
dataType: dataType,
data: data,
success: callback,
error: function(xhr, errorType, error) {
alert('Ajax request error, errorType: ' + errorType + ', error: ' + error);
}
});
}
}
AjaxHelper.prototype.get = function (url, data, callback) {
this.ajax(url, 'GET', 'json', data, callback);
}
AjaxHelper.prototype.post = function (url, data, callback) {
this.ajax(url, 'POST', 'json', data, callback);
}
AjaxHelper.prototype.put = function (url, data, callback) {
this.ajax(url, 'PUT', 'json', data, callback);
}
AjaxHelper.prototype.delete = function (url, data, callback) {
this.ajax(url, 'DELETE', 'json', data, callback);
}
AjaxHelper.prototype.jsonp = function (url, data, callback) {
this.ajax(url, 'GET', 'jsonp', data, callback);
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
AjaxHelper.prototype.constructor = AjaxHelper;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//使用样例
//var ajaxHelper = new AjaxHelper();
//ajaxHelper.post(url, data, function(resEventData) {
//});