2014-10-30 20 views
0

我發現我的網站聊天腳本在here 腳本已經工作,並刷新一次信息,但問題是用戶在網上沒有刷新記錄在每一個新用戶的列表在線刷新用戶。AJAX在對話腳本

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

} 
+1

您的函數不會在任何地方顯示響應。 – Barmar 2014-10-30 08:03:41

+0

完整的腳本可以在這裏找到http://forum.codecall.net/topic/49763-simple-chatroom-with-php-jquery/我想在load_users()ajax腳本 – PNBP 2014-10-30 08:09:52

+0

錯過了你可能需要添加一些隨機到'URL'來防止瀏覽器緩存 – RST 2014-10-30 08:11:05

回答

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