-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadData.js
65 lines (56 loc) · 2.48 KB
/
uploadData.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
function startDataUpload() {
// get form values
var name = document.getElementById("name").value;
var surname = document.getElementById("surname").value;
var module = document.getElementById("module").value;
var postString = "name=" + name + "&surname=" + surname + "&module=" + module;
// get the checkbox values - separate them with a | so that they can be
// split later on if necessary
var checkString = "";
for (var i = 1;i< 5;i++){
if (document.getElementById("check"+i).checked === true) {
checkString = checkString +
document.getElementById("check"+i).value + "||"
}
}
postString = postString + "&modulelist="+checkString;
// get the radio button values
if (document.getElementById("morning").checked) {
postString=postString+"&lecturetime=morning";
}
if (document.getElementById("afternoon").checked) {
postString=postString+"&lecturetime=afternoon";
}
// get the select box values
var language = document.getElementById("languageselectbox").value;
postString = postString + "&language="+language;
// get the geometry values
var latitude = document.getElementById("latitude").value;
var longitude = document.getElementById("longitude").value;
postString = postString + "&latitude=" + latitude + "&longitude=" + longitude;
// pop an alert
alert (postString);
// tell the server what type of data we are uploading
processData(postString);
}
// tell the server what type of data we are uploading - edited to upload rather than reflect data
var client; // the global variable that holds the request
function processData(postString) {
client = new XMLHttpRequest();
postString = postString + "&port_id=" + httpPortNumber;
var url = 'http://developer.cege.ucl.ac.uk:'+ httpPortNumber + "/uploadData";
client.open('POST',url,true);
client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
client.onreadystatechange = dataUploaded;
client.send(postString);
}
// create the code to wait for the response from the data server,
// and process the response once it is received
function dataUploaded() {
// this function listens out for the server to say that
// the data is ready - i.e. has state 4
if (client.readyState == 4) {
// change the DIV to show the response
document.getElementById("dataUploadResult").innerHTML = client.responseText;
}
}