2015-11-04 52 views
0

问题是我怎样才能不断地在另一个php文件中显示php文件的结果。基本上我有一个PHP文件,从DB数量的在线用户和另一个显示它的PHP文件中提取。问题是“另一个php文件”使得它需要重新加载页面才能看到更新的在线用户数量。不断在另一个php文件中显示php文件的结果

到目前为止,以此来显示数字:

<div class="side-last-winner"> 
    <div class="chat-scroll"></div> 
<div class="chat-title"> 
    Reload page to see current number of users 
    <div class="chat-o"> 
     <?php 

echo file_get_contents('user_online.php'); php?> 
    </div> 
    </div> 
    <div id="mcaht" class="left-chat"></div> 
    <script> 
load_messes(); 
setInterval(load_messes,5000); 
</script> 

原始文件与工作页面,但不包括用户:

<div class="side-last-winner"> 
    <div class="chat-scroll"></div> 
<!-- <div class="chat-title"> 
    Test 
    <div class="chat-o"> 
     Online: 
     <span class="online-num" id="inf1">0</span> 
    </div> 
    </div>--> 
    <div id="mcaht" class="left-chat"></div> 
    <script> 
load_messes(); 
setInterval(load_messes,5000); 
</script> 

感谢您的帮助。

回答

0

您可以试用setInterval$().load()函数。

<div class="side-last-winner"> 
    <div class="chat-scroll"></div> 
<div class="chat-title"> 
    Reload page to see current number of users 
    <div class="chat-o"> 
     <?php 

echo file_get_contents('user_online.php'); php?> 
    </div> 
    </div> 
    <div id="mcaht" class="left-chat"></div> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"</script> 
<script type="text/javascript"> 
    setInterval(function(){ 
     $.ajax({ 
       url :'user_online.php', 
       beforeSend: function() 
        { 
         $('.chat-o').html('Loading...'); 
        }, 
       success: function() 
        { 
         $('.chat-o').load('user_online.php'); 
        } 
      }); 
    },1000); 
</script> 
+0

是否一直更新它,并一直显示更新,而无需重新加载? – bagda391

+0

这样的代码解决你的答案? – Nere

+0

不,它没有解决我的答案...我需要它显示在线用户的数量始终更新,无需重新加载页面。你给我的基本上只是更新它,但需要重新加载页面才能看到新的号码 – bagda391