How to get the weather information from the web server?

■ Summary
- This code is getting the weather information from KMA sites. (kma.go.kr)

■ Data Format
- http://www.kma.go.kr/wid/queryDFSRSS.jsp

■ Reference Sites
http://www.w3schools.com/xml/dom_httprequest.asp
/***************************************************
*               Javascript File
****************************************************/

var XML_ADDRESS = "http://www.kma.go.kr/wid/queryDFSRSS.jsp";

var xmlhttp,
    xmlDoc,
    dataItem;

xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
    var temperature;

    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        xmlDoc = xmlhttp.responseXML;
        dataItem = xmlDoc.getElementsByTagName('item');

        // Parse the XML data
        temperature  = dataItem[0].getElementsByTagName('temp')[0].childNodes[0].nodeValue;

        xmlhttp = null;
    }
};

xmlhttp.open("GET", XML_ADDRESS, false);

xmlhttp.send();



/***************************************************
*                    Config.xml
****************************************************/

<tizen:privilege name="http://tizen.org/privilege/internet"/>
<access origin="http://www.kma.go.kr" subdomains="true"></access>

Responses

0 Replies