-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyAJAX.js
28 lines (28 loc) · 887 Bytes
/
EasyAJAX.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
/* Por Bruno Bonavigo, 2021. https://github.com/Bonavigo */
easyAJAX = {
GET(url, func_success, func_error) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
func_success(xhttp.response);
} else if (xhttp.readyState == 4 && xhttp.status !== 200) {
func_error();
}
};
xhttp.open("GET", url, true);
xhttp.send();
},
POST(url, post, func_success, func_error) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
func_success(xhttp.response);
} else if (xhttp.readyState == 4 && xhttp.status !== 200) {
func_error();
}
};
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(post);
}
}