我想顯示在我的網站上實際上有多少人在線。然而,ajax代碼在我的div中沒有顯示任何內容,我不確定這是爲什麼。這個ajax計數器爲什麼不顯示?
<script type="text/javascript">
$(document).ready(function() {
//START After 5 minutes update database timestamp (this part of script works)
fnShowImOnline();
setInterval('fnShowImOnline', 120000);
function fnShowImOnline() {
$.get('counter_im_online.php');
}
//END
{
$.ajax({url: 'counter_members_online.php', dataType: 'json', success: function(response) {
if (isNumeric(response.total)) {
$('#OnlineTotal').html(response.total + " Total ");
$('#OnlineNow').html(response.online + " Online Now");
}
}
});
</script>
<div id="OnlineTotal"></div><div id="OnlineNow"></div>
<?php
// Contents of counter_members_online.php:
// Members online.
$online_sql = "SELECT COUNT(*) FROM users where last_checked_in > DATE_SUB(NOW(), INTERVAL 5 MINUTE)";
$online_RS = mysql_query($online_sql);
$online_row = mysql_fetch_row($online_RS);
$online = $online_row[0];
// Members total.
$total_sql = "SELECT COUNT(*) FROM users";
$total_RS = mysql_query($total_sql);
$total_row = mysql_fetch_row($total_RS);
$total = $total_row[0];
$response = json_encode(array('total'=>$total,'online'=>$online));
echo($response);
?>
我建議您分析http流量與螢火蟲。然後回髮結果,這將有助於放棄哪一方(服務器或客戶端)產生錯誤。 – 2014-09-27 22:41:37