Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <ul class="itemlist">
</ul>
              
            
!

CSS

              
                
              
            
!

JS

              
                (function() {
  let epaAPI = "http://opendata.epa.gov.tw/ws/Data/UV/?$orderby=PublishAgency&$skip=0&$top=1000&format=json&callback=?";
  let errorUrl = "http://opendata.epa.gov.tw/ws/Data/UL/?$orderby=PublishAgency&$skip=0&$top=1000&format=json&callback=?";
  let _DefaultContry = '臺北市';
  
  var getData = (url)=> { // 傳入的 URL
    return new Promise((resolve, reject) => { // return promise
      $.getJSON( url, function(){
        format: "json"
      }).done(function(data) {
        if (data) {
          resolve(data); // 成功後透過 resolve 回傳值
        } else {
          reject('Error');
        }
      }).fail(function() {
        reject('Error');
      });
    });
  }
  
  getData(epaAPI) // 傳入的 url
    .then((data)=>{ // then 接受回傳的值
      console.log(data);
      $.each( data, function( i, item ) {
        console.log(item);

        let list = `<li>${item.SiteName} ${item.PublishTime} ${item.SiteName} ${item.UVI}</li>` 
        //利用item.值,把每一個值取出,並寫成一個html存在list的變數內

        $('.itemlist').append(list);
        //最後把剛剛的html放到表格內
      });
    });
  
  getData(errorUrl) // 傳入錯誤的 url
    .then((data)=>{ // then 接受回傳的值 (錯誤的狀況不會跑這段)
      console.log(data);
    })
    .catch((response)=> { // 錯誤狀態的回傳
      console.log('errorUrl:', response);
    });
  
})();
              
            
!
999px

Console