0

I created ajax to get start time and end time from another page and setInterval for this function every second like this.

setInterval(function () {
    CheckTime()
}, 1000);

function CheckTime() {
    $.ajax({
        url: "Get_TIme.php",
        success: function (result) {
            var time = result.split('|');
            var start_time = time[0];
            var end_time = time[1];

            var getTime = new Date();
            var currentHours = getTime.getHours();
            var currentMinutes = getTime.getMinutes();
            var currentTime = currentHours + ":" + currentMinutes;

            if ((currentTime == start_time) || (currentTime == end_time)) {
                $('#first').load('demo.php #first'); //reload div
            }
        }
    });

At first time when current time = start time, <div> can refresh itself. But when current time = end time, <div> doesn't reload itself. I don't what happen on this code. But I replace alert before if((currentTime==start_time)||(currentTime==end_time)) like this:

alert("something");
if((currentTime==start_time)||(currentTime==end_time))
{
   $('#first').load('demo.php #first'); //reload div
} 

<div> can reload itself when current time = end time. Anyone can suggest me what happen on my code.

Magnus Engdal
  • 5,446
  • 3
  • 31
  • 50
  • I don't think .load() will work in an ajax() cause it is like an ajax call. load() might works if u use it oustide the ajax function? read this: http://stackoverflow.com/questions/3870086/difference-between-ajax-and-get-and-load – caramba Dec 20 '13 at 07:36

2 Answers2

1

I think load must be use like that :

$('#first').load('demo.php');

this is what I saw in the documentation here

kevpoccs
  • 635
  • 5
  • 8
0

Try this:

if((currentTime==start_time)||(currentTime==end_time))
{
   $('#first').load('demo.php'); //reload div
} 

if you want show #first use following;

$(document).ready(function(){

         $("#first").css("class","active");
}
Mr.G
  • 3,413
  • 2
  • 16
  • 20