-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpRequester.js
45 lines (42 loc) · 1.21 KB
/
httpRequester.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
define(['scripts/jquery-2.1.1.min', 'scripts/rsvp'], function () {
window.httpRequester = (function () {
function getJSON(requestUrl) {
var promise = new RSVP.Promise(function (resolve, reject) {
$.ajax({
url: requestUrl,
type: "GET",
dataType: "json",
success: function (data) {
resolve(data);
},
error: function (err) {
reject(err);
}
});
});
return promise;
}
function postJSON(requestUrl, data) {
var promise = new RSVP.Promise(function (resolve, reject) {
$.ajax({
url: requestUrl,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data),
dataType: "json",
success: function (data) {
resolve(data);
},
error: function (err) {
reject(err);
}
});
});
return promise;
}
return {
getJSON: getJSON,
postJSON: postJSON
}
}());
});