Php 为什么赢了';这不是ajax计数器显示吗?
我想显示有多少人在我的网站上在线。但是ajax代码在我的div中没有显示任何内容,我不知道为什么会这样Php 为什么赢了';这不是ajax计数器显示吗?,php,ajax,Php,Ajax,我想显示有多少人在我的网站上在线。但是ajax代码在我的div中没有显示任何内容,我不知道为什么会这样 <script type="text/javascript"> $(document).ready(function() { //START After 5 minutes update database timestamp (this part of script works) fnShowImOnline(); setInterval('fnShowImOnl
<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);
?>
$(文档).ready(函数(){
//5分钟后开始更新数据库时间戳(脚本的这部分工作)
fnShowImOnline();
设定间隔('fnShowImOnline',120000);
函数fnShowImOnline(){
$.get('counter_im_online.php');
}
//结束
{
$.ajax({url:'counter\u members\u online.php',数据类型:'json',success:function(response){
如果(是数字(响应总数)){
$('#OnlineTotal').html(response.total+“total”);
$('#onlineow').html(response.online+“online Now”);
}
}
});
这个代码不应该吗
$.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");
}
}
});
是函数fnShowImOnline()的一部分
i、 e.函数fnShowImOnline
应为
function fnShowImOnline() {
$.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 type="text/javascript">
$(document).ready(function() {
//START After 5 minutes update database timestamp (this part of script works)
fnShowImOnline();
setInterval('fnShowImOnline', 120000);
});
function fnShowImOnline() {
$.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>
$(文档).ready(函数(){
//5分钟后开始更新数据库时间戳(脚本的这部分工作)
fnShowImOnline();
设定间隔('fnShowImOnline',120000);
});
函数fnShowImOnline(){
$.ajax({url:'counter\u members\u online.php',数据类型:'json',success:function(response){
如果(是数字(响应总数)){
$('#OnlineTotal').html(response.total+“total”);
$('#onlineow').html(response.online+“online Now”);
}
}
});
}
我解决了问题。下面的脚本现在可以工作了,$.ajax部分之前有一个},但它不工作:
<script type="text/javascript">
$(document).ready(function() {
// After 5 minutes update database timestamp (this part of script works)
fnShowImOnline();
setInterval('fnShowImOnline', 120000);
});
function fnShowImOnline() {
$.get('counter_im_online.php');
}
$.ajax({
url: 'counter_members_online.php',
dataType: 'json',
success: function(response) {
if (!isNaN(response.total)) {
$('#OnlineTotal').html(response.total + " Total ");
$('#OnlineOnline').html(response.online + " Members Online");
}
}
})
</script>
$(文档).ready(函数(){
//5分钟后更新数据库时间戳(这部分脚本有效)
fnShowImOnline();
设定间隔('fnShowImOnline',120000);
});
函数fnShowImOnline(){
$.get('counter_im_online.php');
}
$.ajax({
url:“counter_members_online.php”,
数据类型:“json”,
成功:功能(响应){
如果(!isNaN(响应总数)){
$('#OnlineTotal').html(response.total+“total”);
$('#online online').html(response.online+“会员在线”);
}
}
})
我建议您使用firebug分析http流量。然后发回结果,这将有助于丢弃产生错误的那一方(服务器或客户端)。我尝试删除}//END{,使其成为该函数的一部分,但仍然不起作用。请尝试在isNumeric()之前执行console.log(response);然后执行行并查看firefox/chrome中的响应,然后让我们知道您看到了什么好的如果我点击f12我得到:未捕获类型错误:未定义不是函数(索引):143未捕获语法错误:输入意外结束(索引):1加载资源失败:net::ERR\u被\u CLIENTI阻止了\u我刚刚编辑了你所有脚本标记的答案,你能检查它,相应地修改你的代码,然后告诉我你看到了什么它不起作用。我还用console.log(response)尝试了它;这次没有给我任何错误,但它仍然没有显示联机计数。