2013-12-20 36 views
0

我創建了ajax來從另一個頁面獲取開始時間和結束時間,並且每秒鐘都會爲此函數設置setInterval。.load不刷新我的div

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 
      } 
     } 
    }); 

在第一次時current time = start time<div>可以刷新自己。但是當current time = end time,<div>不重新加載自己。我不會在這個代碼上發生什麼。但我if((currentTime==start_time)||(currentTime==end_time))這樣之前更換警報:

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

<div>可以在current time = end time重新加載自身。任何人都可以建議我在我的代碼上發生什麼。

+0

我不認爲.load()將在ajax()中工作,因爲它就像一個ajax調用。 load()可能工作,如果你用它oustide ajax函數?閱讀此:http://stackoverflow.com/questions/3870086/difference-between-ajax-and-get-and-load – caramba

回答

1

我想負荷必須這樣使用:

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

這是我的文檔中看到here

+0

當currentTime = end_time仍然無法正常工作。 –

0

試試這個:如果你想顯示

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

#第一次使用以下內容;

$(document).ready(function(){ 

     $("#first").css("class","active"); 
}