我試圖使用ajax函數顯示數據庫值。當我向數據庫表中添加新行時,它不會立即顯示記錄。我必須刷新我的頁面。然後只顯示最近的日誌細節。我認爲我有一個Ajax編碼的問題。我是ajax的新手。有人幫我解決我的問題..數據庫記錄顯示沒有使用ajax刷新頁面
function updateDriver(event)
{
$(".panel a").each(function(){
if($(this).hasClass("active"))
$(this).removeClass("active");
});
$(this).addClass("active");
ajaxObj.options.previousDriver = ajaxObj.options.data['did'];
ajaxObj.options.data = {'aid':'<?=$agent_id?>','did': event.data.did};
//Ajax call for Driver Log Update;
//function refreshEachMinute() {
$("#RecentLog").html('Loading...');
$.ajax({
url: "<?=LOAD_LOG?>/",//The resource that delivers loc data.
method: 'post', //data method
dataType:'html',
data: { aid: "<?=$agent_id?>", did: event.data.did },
success: function(data)
{
$('#RecentLog').html(data);
},
error: function()
{
$('#RecentLog').html('<p>No Entries</p>')
}
});
//}
//setInterval(refreshEachMinute, 200);
}
PHP
case LOAD_LOG:
if(!isset($_POST['aid']))
die();
$agent_id = $_POST['aid'];
$driver_id = $_POST['did'];
$sql = "SELECT * FROM ".TBL_DRIVER_LOG." where driver_id='$driver_id' ORDER BY id DESC";
$log_data = asort_result_array($sql);
$driver_log ="";
if(count($log_data))
foreach($log_data as $log)
{
extract($log);
$ago = TimeAgo($date_of_update);
echo '<p>
<span>'.$ago.', @ '.$average_speed.'km/hr</span><br>
<span style="font-size: 13px; font-weight: normal;">'.$current_place.'</span>
</p>
<hr class="tabhr">';
}
else
echo "No Entries";
exit();
使用的setTimeout來代替setInterval的?我的意思是有任何請求這個Ajax的點擊事件? – Jai
@jai:我已經更新了我的ajax代碼.. – Karuppiah