-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAjaxHelper.js
75 lines (71 loc) · 1.77 KB
/
AjaxHelper.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c) 2021 Lenze SE
* SPDX-License-Identifier: Apache-2.0
*/
class AjaxHelper {
constructor() {
/* AJAX */
this.getJSON = this.getJSON.bind(this);
this.putJSON = this.putJSON.bind(this);
this.postJSON = this.postJSON.bind(this);
}
getJSON(URL,
callback_success,
callback_error,
ctx = null) {
$.ajax({
url: URL,
type: 'GET',
dataType: 'json',
crossDomain: true,
success: callback_success,
error: callback_error,
context: ctx
});
return true;
}
putJSON(URL,
value,
callback_success,
callback_error,
ctx = null) {
$.ajax({
url: URL,
type: 'PUT',
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type", "application/json");
if (xhr.overrideMimeType) {
xhr.overrideMimeType("application/json");
}},
dataType: 'json',
crossDomain: true,
success: callback_success,
error: callback_error,
data: value,
context: ctx
});
return true;
}
postJSON(URL,
value,
callback_success,
callback_error,
ctx = null) {
$.ajax({
url: URL,
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type", "application/json");
if (xhr.overrideMimeType) {
xhr.overrideMimeType("application/json");
}},
dataType: 'json',
crossDomain: true,
success: callback_success,
error: callback_error,
data: value,
context: ctx
});
return true;
}
}