-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.js
32 lines (30 loc) · 970 Bytes
/
monitor.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
// Self-invoking function
(function() {
window.onload = function() {
function loadJSON(callback){
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'js/output.json', true);
xobj.onreadystatechange = function() {
if (xobj.readyState == 4 && xobj.status == "200") {
callback(xobj.responseText);
}
};
xobj.send(null);
}
// More stuff
loadJSON(function(response) {
var result = JSON.parse(response);
// Get spans in html
var temp = document.getElementById('temp');
var high = document.getElementById('high');
var low = document.getElementById('low');
var hum = document.getElementById('hum');
// Populate json data into html
temp.textContent = result.currentTemp.toFixed(1) + '*F.';
high.textContent = result.todaysHigh.toFixed(1) + '*F.';
low.textContent = result.todaysLow.toFixed(1) + '*F.';
hum.textContent = result.currentHumidity.toFixed(1) + '%.';
});
}
})();