what have i missed

what have i missed

What have i done wrong here

Thanks Beau

  1. window.onload = function() {
  2.     var updateTimer;
  3.     var cp = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];

  4.     $('[id$=Table]').DataTable({
  5.         'paging': false,
  6.         'searching': false,
  7.         'info': false,
  8.         'ordering': false
  9.     });

  10.    

  11.     function updateTimeout() {
  12.         // Change the icon on the last update to show that there has been no update for a while
  13.         $('#LastUpdateIcon').attr('src', 'img/down.png');
  14.     }

  15.    
  16.    
  17.         var data = JSON.parse(mydata);

  18.         // restart the timer that checks for the last update
  19.         window.clearTimeout(updateTimer);
  20.         updateTimer = setTimeout(updateTimeout, 60000);

  21.         // Get the keys from the object and set
  22.         // the element with the same id to the value
  23.         Object.keys(data).forEach(function(key) {
  24.             var id = '#' + key;
  25.             if ($(id).length) {
  26.                 $(id).text(data[key]);
  27.             }
  28.         });

  29.         $('#BearingCP').html(cp[Math.floor(((parseInt(data.Bearing) + 11) / 22.5) % 16)]);
  30.         $('#AvgbearingCP').html(cp[Math.floor(((parseInt(data.Avgbearing) + 11) / 22.5) % 16)]);

  31.         $('.WindUnit').text(data.WindUnit);
  32.         $('.PressUnit').text(data.PressUnit);
  33.         $('.TempUnit').text(data.TempUnit);
  34.         $('.RainUnit').text(data.RainUnit);

  35.         var lastupdatetime = new Date();
  36.         var hours = lastupdatetime.getHours();
  37.         var minutes = lastupdatetime.getMinutes();
  38.         var seconds = lastupdatetime.getSeconds();

  39.         if (hours < 10) {
  40.             hours = '0' + hours;
  41.         }
  42.         if (minutes < 10) {
  43.             minutes = '0' + minutes;
  44.         }
  45.         if (seconds < 10) {
  46.             seconds = '0' + seconds;
  47.         }

  48.         var time = hours + ':' + minutes + ':' + seconds;

  49.         $('#lastupdatetime').text(time);
  50.    

  51.    
  52.     
  53. $.ajax({
  54.        url: './realtime2.php',
  55.        dataType: 'json',
  56.        success: function(mydata) {
  57.        console.log(mydata)   
  58.        }
  59.    });
}