0

I found this Jquery/Ajax call with timer but for my case, i think i cannot help.

I've more then 3 panels to update with ajax and this number will keep growing. If that request are make at same time i can resolve using http://api.jquery.com/jQuery.when/ but this panels have differents timers to be executed...

The first every 10sec. The second every 3sec. The third every 30sec.

It will reach at moment on every one will be executed at the same time... But how this will keep growing...

I've think in one way creating a stack that should be executed using http://api.jquery.com/jQuery.when/ every 1sec.

I believe that another alternatives to implement this...

Some one get different solution?

/**
 * Method to display method information.
 */
function updateServerStatus()
{
    /**
     * Performs ajax request to return the json.
     * NOTES: 'server.load.php' send a json object about server status using false to 'offline' and 'true' to 'online' status.
     */
    $.ajax({
        'url' : 'server.load.php',
        'data' : 'json',
        success : function(objServer)
        {
            /**
             * Removes style showing color about status.
             */
            $('#map-status, #char-status, #login-status').removeClass('label-danger').removeClass('label-success');

            /**
             * Check if map-server is offline.
             */
            if(objServer.map == false)
            {
                $('#map-status').addClass('label-danger').html('Offline');
            }
            else
            {
                $('#map-status').addClass('label-success').html('Online');
            }

            /**
             * Check if char-server is offline.
             */
            if(objServer.char == false)
            {
                $('#char-status').addClass('label-danger').html('Offline');
            }
            else
            {
                $('#char-status').addClass('label-success').html('Online');
            }

            /**
             * Check if char-server is offline.
             */
            if(objServer.login == false)
            {
                $('#login-status').addClass('label-danger').html('Offline');
            }
            else
            {
                $('#login-status').addClass('label-success').html('Online');
            }
        }
    });

    /**
     * Get into loop calling this after 10sec to keep updated.
     */
    setTimeout(updateServerStatus, 10000);
};

@SOLVED

I've solved it using array stack.

Community
  • 1
  • 1
Carlos
  • 63
  • 8
  • 2
    Show us your code first. – Reinstate Monica Cellio Oct 03 '13 at 13:01
  • You could use JavaScripts's setInterval, e.g for panel 1: setInterval(UpdatePanel1(), 10000); For panel 2 : setInterval(UpdatePanel2(), 3000); Would need to see some code to get a better view of what it is you're doing. – JBeagle Oct 03 '13 at 13:12
  • The code is posted. the others panels, it almost same think with de same call... but, setInterval on some browsers will update only if the window get focus and that is not my objective. – Carlos Oct 03 '13 at 13:18
  • Check out this http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome/7387953#7387953 for your gripes with browser focus and setInterval. – JBeagle Oct 03 '13 at 13:24
  • Hm... it help a little but i'm still searching a solution to execute "on same time" – Carlos Oct 03 '13 at 13:32
  • As a side note you are using double equals in your comparisons, e.g. "if(objServer.login == false)". It is safer to use "===". See http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons. – JBeagle Oct 03 '13 at 13:51
  • Thanks but in this case, it only will return true or false. No need, in this case, test if is exactly true or exactly false... – Carlos Oct 03 '13 at 14:06
  • Web Workers works fine for me. – Carlos Dec 18 '13 at 13:57

0 Answers0