-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.js
29 lines (26 loc) · 927 Bytes
/
ajax.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
function ajaxGetRequest(path, callback) {
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState===4 && this.status ===200) {
callback(this.response);
}
}
request.open("GET", path);
request.send();
}
// path -- string specifying URL to which data request is sent
// data -- JSON blob being sent to the server
// callback -- function called by JavaScript when response is received
function ajaxPostRequest(path, data, callback) {
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState===4 && this.status ===200) {
callback(this.response);
}
}
request.open("POST", path);
request.send(data);
}
// function getme(jsonthing){
// ajaxGetRequest("/wantsomedata")
// }