dph6308 2015-11-04 07:10
浏览 87

在同一个php文件中使用js加载

<script>
 setInterval(function(){
         $.ajax({
               url :'user_online.php',

               success: function()
                   {
                       $('.chat-o').load('user_online.php');
                   }
            });
     },1000); 
</script>

Let's say I have this script. How do I make it work if user_online is the file I put this in (meaning, how can I make this script work internally-- within a php file called the same as the url)

Basically I want to apply the same thing as above to another page make it auto display the results without having to reload it:

<?php 
   $gameid = fetchinfo("value", "info", "name", "current_game");
$query  = mysql_query("SELECT * FROM `games` WHERE `id` < $gameid ORDER BY `id` DESC LIMIT 10");
while($rowd=mysql_fetch_array($query)):
  //define stuff
  $lastwinner=$rowd["userid"];
  $winnercos =$rowd['cost'];
  $winnerpercent = $rowd['percent'];
  $winneravatar=fetchinfo("avatar", "users", "steamid", $lastwinner);
  $winnername = fetchinfo("name", "users", "steamid", $lastwinner);
  $steamlink = fetchinfo("steamprofile", "users", "steamid", $lastwinner); ?>
  <div class="cont row">
  <div class="col-xs-24 header">
  </div>
  <div class="col-xs-24 body">
  <div class="col-xs-16 col-sm-16">
  <a rel="nofollow" target="_blank" href=<?php echo $steamlink; ?> class="img hidden-xs">
  <img src=<?php echo $winneravatar; ?> > </a>
  <a rel="nofollow" target="_blank" href=<?php echo $steamlink; ?> class="name"> <?php echo $winnername; ?> </a>
  </div>
  <div class="right text-right">
  <span class="win">
  Win: <span>$ <?php echo round($winnercos, 3); ?> </span></span>
  <span class="chance">
  Chance: <span><?php echo round($winnerpercent, 2); ?>% </span> </span> </div> </div>

Updated it with what I wanted. Can anyone tell me if it's ok? This is from one part of index.php

 <div class="site history col-xs-24 col-sm-18 col-md-14 col-lg-12"> <h2>History</h2> <div id="history">
  <script>
 setInterval(function(){
         $.ajax({
               url :'index.php',

               success: function()
                   {
                       $('.history').html(data);
                   }
            });
     },1000); 
</script> 
   <?php 
   $gameid = fetchinfo("value", "info", "name", "current_game");
$query  = mysql_query("SELECT * FROM `games` WHERE `id` < $gameid ORDER BY `id` DESC LIMIT 10");
while($rowd=mysql_fetch_array($query)):
  //define stuff
  $lastwinner=$rowd["userid"];
  $winnercos =$rowd['cost'];
  $winnerpercent = $rowd['percent'];
  $winneravatar=fetchinfo("avatar", "users", "steamid", $lastwinner);
  $winnername = fetchinfo("name", "users", "steamid", $lastwinner);
  $steamlink = fetchinfo("steamprofile", "users", "steamid", $lastwinner); ?>
  <div class="cont row">
  <div class="col-xs-24 header">
  </div>
  <div class="col-xs-24 body">
  <div class="col-xs-16 col-sm-16">
  <a rel="nofollow" target="_blank" href=<?php echo $steamlink; ?> class="img hidden-xs">
  <img src=<?php echo $winneravatar; ?> > </a>
  <a rel="nofollow" target="_blank" href=<?php echo $steamlink; ?> class="name"> <?php echo $winnername; ?> </a>
  </div>
  <div class="right text-right">
  <span class="win">
  Win: <span>$ <?php echo round($winnercos, 3); ?> </span></span>
  <span class="chance">
  Chance: <span><?php echo round($winnerpercent, 2); ?>% </span> </span> </div> </div>
  • 写回答

1条回答 默认 最新

  • duankui6150 2015-11-04 07:12
    关注

    You have already used ajax to do something in user_online.php, so need to load the data again in .load(). So

    Change this,

    success: function(data)
         {
             $('.chat-o').html(data);
         }
    

    If you are using only php in user_online.php, make sure you echo the values.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路