-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 880 Bytes
/
index.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
var BluebirdPromise = require('bluebird');
var $ = require('jquery');
var AjaxPromise = {
ajax: function (type, url, data) {
return new BluebirdPromise(function (resolve, reject) {
var opts = {
type: type,
dataType: 'JSON',
success: resolve,
error: function (jqXHR) {
reject(jqXHR);
}
};
opts.data = data;
return $.ajax(url, opts);
});
},
get: function (url, data) {
return this.ajax('GET', url, data);
},
post: function (url, data) {
return this.ajax('POST', url, data);
},
put: function (url, data) {
return this.ajax('PUT', url, data);
},
patch: function (url, data) {
return this.ajax('PATCH', url, data);
},
delete: function (url, data) {
return this.ajax('DELETE', url, data);
}
};
module.exports = AjaxPromise;