-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLASSjson.html
45 lines (44 loc) · 1.31 KB
/
LASSjson.html
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
<html><head><title>Test access to LASS JSON data</title></head>
<body>
<p>LASS Air Quality</p>
<p>PM 2.5 for device FT1_333 is:
<span id="pm25">(my PM2.5 data should go here)</span>
at this time:
<span id="datatime">(my time info should go here)</span>
</p>
<script>
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};
//var url = 'http://nrl.iis.sinica.edu.tw/LASS/history.php?device_id=FT1_333';
var url = 'http://nrl.iis.sinica.edu.tw/LASS/last.php?device_id=FT1_333';
var method = 'GET';
console.log('Create CORS XMLHttpRequest ', method, url);
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
console.log('Success', xhr);
var data = JSON.parse(xhr.responseText);
document.getElementById('pm25').innerText = data.s_d0;
document.getElementById('datatime').innerText = data.timestamp;
console.log('data', data);
};
xhr.onerror = function() {
console.log('Error', xhr);
};
console.log('Send CORS request');
xhr.send();
console.log('done');
</script>
</body></html>