Advertisement
jrrewers

Untitled

Feb 13th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.  
  3.     // variables for DOM
  4.     var $select = $("select");
  5.     var $h1 = $("h1");
  6.  
  7.     //variables for url
  8.     var holidayUrl = 'https://holidayapi.com/v1/holidays?key=dba66ef9-c647-4829-9f65-71d0279eed85&country=PL&year=2016';
  9.  
  10.     function insert(holidays) {
  11.         $.each(holidays, function(i, holiday) {
  12.             var option = $('<option name = ${"holidays.name"}>holiday.date</option>')
  13.  
  14.             /* poprawnie */
  15.             var option = $(`<option name = ${holidays.name}>${holiday.date}</option>`)
  16.            
  17.  
  18.             $h1.text('ŚwiΔ™ta w Polsce w 2016 roku');
  19.             $select.append(option);
  20.             $('div').append($h1);
  21.  
  22.         })
  23.     }
  24.  
  25.     function loadHolidays() {
  26.         $.ajax({
  27.             url: holidayUrl,
  28.             type: 'get'
  29.         }).done(function(holidays) {
  30.             insert(holidays);
  31.             console.log(holidays);
  32.         }).fail(function(error) {
  33.             console.log(error);
  34.         })
  35.     }
  36.  
  37.     $select.on('click', function(e) {
  38.         loadHolidays();
  39.     });
  40.  
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement