Need other way to show running time left

First of all Hello!
In my website i have game, every 15min i have new draw, and when people come to website they see how much time is left.
It work Now (Jquery/Ajax):

  1. Take information every second from Memchached and Run.
  2. When time left is “00:00” => run some script and continue again (1.)

How to change this to other way ? To do time run, and without send query every second to check the time left. Or just optimization the code. Here is the code, that i use.

jQuery(function ($) {
    function InfoTime() {
        var stat = ['table_for_timer'];
        var url = 'game_run_script.php?' + Math.random();
        $.each(stat, function (i, key) {
            $.post(url, {
                cache: false,
                stats: key
            }, function (data) {
                if (data === "00:00") {
                    $.ajax({
                        url: 'run_action_script.php?' + Math.random(),
                        type: 'GET',
                        cache: false,
                        data: '',
                        success: function (data) {
                            $('#showinfo').html(data);
                            $('#something').load('something.php?' + Math.random());
                            return false;
                        }
                    });
                }
                $("#" + key).html(data);
            });
        });
    }
    setInterval(InfoTime, 1000);
});

In this website i found running time left (like what i need) http://cafe.inbet.cc/keno u can see Time before start: 1:25 , but I do not understand how it works there.

Thanks

How you can do that is to retrieve (once) from the server the time that the game will start, and to then use setTimeout or setInterval to update an onscreen countdown that shows the difference in time between now and that date you retrieved from the server.

I am use CronTab to run one time every 15min some script to show new results, checks and give new time. (PHP/MYSQLI) , after this results go to MEMORY with memcatched. And from memcatched its will come show to the all website with JS (run with setInterval). Example http://goo.gl/r9MdxT

I try now another way

var next_time_draw = new Date('December 22, 2014 19:00:00').getTime();
var minutes, seconds;
var countdown = document.getElementById('countdown');

    setInterval(function () {
        var current_date = new Date().getTime();
        var seconds_left = (next_time_draw - current_date) / 1000;
        minutes = parseInt(seconds_left / 60);
        seconds = parseInt(seconds_left % 60);
        countdown.innerHTML = minutes + ":" + seconds;
        if (minutes <= "0" && seconds <= "0") {
            // Here is Action effect and reload objects
           /* $.ajax({
                            url: 'run_action_script.php?' + Math.random(),
                            type: 'GET',
                            cache: false,
                            data: '',
                            success: function (data) {
                                $('#showinfo').html(data);
                                $('#something').load('something.php?' + Math.random());
                                return false;
                            }
                        }); */
        }
    }, 1000);

But i don’t know how to do, that var next_time_draw will updated all the time, and take information from database/cache or memcached.
If i will place the var next_time_draw on same page (like head.php) it’s will not show and get new time var if people do not refresh the page.
To take var next_time_draw from another page, it will be like my script before, every second send query to check correct time left.

Any idea maybe ? Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.