我在here找到了我网站的聊天脚本 该脚本已经工作并刷新每条消息,但问题是用户在线列表没有刷新每个登录的新用户。
ajax代码
// Now let's load chatroom's active users
function load_users(){
// Let's use AJAX also to get chatroom's users
$.ajax({
url: "includes/actions.php?act=getusers",
cache: false
});
}
setInterval(load_messages, 500);
setInterval(load_users, 500);
actions.php脚本
function get_users(){
global $tb_satker;
// Let's get all info from "auth" table
$sql = "SELECT * FROM $tb_satker WHERE status!=''";
$query = mysql_query($sql);
if(!$query){
echo "Can not get users from database.";
}else{
while($row = mysql_fetch_array($query)){
$namasatker=$row['nama_satker'];
echo "<li><i class=\"icon-user\"></i>$namasatker</li>";
}
}
}
答案 0 :(得分:2)
您需要一个显示返回HTML的成功函数:
function load_users(){
// Let's use AJAX also to get chatroom's users
$.ajax({
url: "includes/actions.php?act=getusers",
cache: false,
success: function(response) {
$("#onlineusers").html(response);
}
});
}