-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 707 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 707 Bytes
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
//GET Request
function GETrequest(URL,callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//Action
callback(this.responseText);
}
};
xhttp.open("GET", URL, true);
xhttp.send();
}
//POST
function POSTrequest(URL,obj,callback) {
var objJSON = JSON.stringify(obj);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(this.responseText);
}
};
xhttp.open("POST", URL, true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.send(objJSON);
}