Author Topic: what did I do wrong  (Read 605 times)

0 Members and 1 Guest are viewing this topic.

Offline n9mfk9

  • Contributor
  • ***
  • Posts: 112
what did I do wrong
« on: May 27, 2015, 12:55:37 PM »

Where have i gone wrong I see the data but can not use it in the code
http://n9mfk.info/newidea/mynow3.html

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

    $('[id$=Table]').DataTable({
        'paging': false,
        'searching': false,
        'info': false,
        'ordering': false
    });

   

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

   
var data = returndata();
   
        var data = JSON.parse(data);

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

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

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

        $('.WindUnit').text(data.WindUnit);
        $('.PressUnit').text(data.PressUnit);
        $('.TempUnit').text(data.TempUnit);
        $('.RainUnit').text(data.RainUnit);

        var lastupdatetime = new Date();
        var hours = lastupdatetime.getHours();
        var minutes = lastupdatetime.getMinutes();
        var seconds = lastupdatetime.getSeconds();

        if (hours < 10) {
            hours = '0' + hours;
        }
        if (minutes < 10) {
            minutes = '0' + minutes;
        }
        if (seconds < 10) {
            seconds = '0' + seconds;
        }

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

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

   
    function returndata() {
$.ajax({
       url: './realtime2.php',
       dataType: 'json',
       success: function(data) {
       console.log(data)   
       }
   });
};
return data;
}