-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverComm.js
executable file
·68 lines (64 loc) · 1.86 KB
/
serverComm.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
var serverComm = {};
serverComm.logging = false;
serverComm.register_subject = function(subject_id, callback_continue, callback_exclude, callback_failure){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'php/exclude/check_subject_exclusion.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if(xhr.status == 200){
var response = JSON.parse(xhr.responseText);
if(serverComm.logging){
console.log(response);
}
if(response.success){
if(response.exclude){
callback_exclude(response);
} else {
callback_success(response);
}
} else {
callback_failure();
}
}
};
xhr.onerror = function(){
callback_failure();
}
xhr.send(JSON.stringify({id: subject_id}));
}
serverComm.assign_condition = function(subject_id, n_conditions, callback_success, callback_failure){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'php/assign/assign_subject_condition.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if(xhr.status == 200){
var response = JSON.parse(xhr.responseText);
if(serverComm.logging){
console.log(response);
}
if(response.success){
callback_success(response);
} else {
callback_failure();
}
}
};
xhr.onerror = function() {
callback_failure();
}
xhr.send(JSON.stringify({n_conditions: n_conditions, id: subject_id}));
}
serverComm.save_data = function(data){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'savedata.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if(xhr.status == 200){
var response = JSON.parse(xhr.responseText);
if(serverComm.logging){
console.log(response);
}
}
};
xhr.send(JSON.stringify(data));
}