政府Opendata使用jQuery的範例(JSON)

以台南市公廁地址的開啟資料為例
執行結果如下圖:


程式碼如下:
=================================================
<!DOCTYPE html>

<html>
    <head>  
          <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <title>TESTING</title>
    </head>
   
     <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.4.4.min.css" />
   
    <body>
         <section id="test01"> 按我測試 </section>
          <section id="clock02"></section>
          <section id="clock_st01"></section>
     </body>
</html>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>

<script type="text/javascript">  
          //設定參數    
          var data1 = {
                //公開資料的來源ID
                resource_id: 'bde652b1-90d8-4b90-8ab4-f8bdc19242fc',
                limit: 5, // get 5 results
                q: '3' // query for '3'
                };
        $.ajax({
            url: 'http://data.tainan.gov.tw/api/action/datastore_search',
            data: data1,
            dataType: 'jsonp',
            success: function(data1) {
                //依下圖Chrome瀏覽器的開發工具可得知,
                //如果要找「公廁名稱」,回傳的資料為result物件底下的
                //records陣列物件,key為「公廁名稱」
                alert(data1.result.records[1].公廁名稱)
            }
        });
       
     });
</script>


Windows 11安裝時跳過網路連線