-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemperatureVariation.js
57 lines (50 loc) · 1.7 KB
/
TemperatureVariation.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
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if(window.ActiveXObject){
//Internet Explorer
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = false;
}
}else{
//Other browsers
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}
if(!xmlHttp){
alert("Can not create xmlHttp object!")
}else{
return xmlHttp;
}
}
function process(){
if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
loc = encodeURIComponent(document.getElementById("location").value);
date = encodeURIComponent(document.getElementById("date").value);
xmlHttp.open("GET", "AirComposition.php?loc="+loc+"&date="+date, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}else{
//setTimeout('process()', 1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
var message = xmlDocumentElement.firstChild.data;
var result = message.split(":");
//document.getElementById("oxygenPercentage").innerHTML = '<span style="color:white">' + message + '%</span>';
document.getElementById("oxygenPercentage").innerHTML = '<span>'+result[0]+'%</span>';
document.getElementById("nitrogenPercentage").innerHTML = '<span>'+result[1]+'%</span>';
}else{
alert("Something went wong");
}
}
}