-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex11-2.html
37 lines (37 loc) · 2.09 KB
/
ex11-2.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
<html>
<title></title>
<head></head>
<body>
<script language="JavaScript">
var xhr = new XMLHttpRequest();
var url = 'http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty'; /*URL*/
var queryParams = '?' + encodeURIComponent('ServiceKey') + '='+'DabzRHmcywzOD2%2B%2FwW45U05QU9qFYv%2FtNYlMz8YEw7ZiBveoPe%2Bx2jYjh3ctcaM7kMWwJoKlAzUNVlFtYzam7A%3D%3D'; /*Service Key*/
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('24'); /**/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /**/
queryParams += '&' + encodeURIComponent('stationName') + '=' + encodeURIComponent('미사'); /**/
queryParams += '&' + encodeURIComponent('dataTerm') + '=' + encodeURIComponent('DAILY'); /**/
queryParams += '&' + encodeURIComponent('ver') + '=' + encodeURIComponent('1.3'); /**/
xhr.open('GET', url + queryParams);
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
alert(this.responseText);
//var xmldoc = new ActiveXObject("MSXML.DOMDocument");
//xmldoc.async = false;
//xmldoc.loadXML(this.responseText);
//var item = xmldoc.selectNodes("//item");
var xmldoc = this.responseXML;
var item = xmldoc.getElementsByTagName("item");
for(var i = 0 ; i < item.length ; ++i )
{
var time = item[i].getElementsByTagName("dataTime");
var pm10 = item[i].getElementsByTagName("pm10Value");
var pm25 = item[i].getElementsByTagName("pm25Value");
alert(time[0].firstChild.nodeValue+": pm10("+pm10[0].firstChild.nodeValue
+"), pm2.5("+pm25[0].firstChild.nodeValue+")");
}
}
};
xhr.send('');
</script>
</body>
</html>