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

时间:2015-11-04 07:10:28

标签: javascript php integrate

<?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>

我们说我有这个剧本。如果user_online是我放入的文件(如何让这个脚本在内部工作 - 在一个名为url的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>

用我想要的更新了它。谁能告诉我它是否可以?这是index.php的一部分

var removedId = 2;
for (var i = 0; i < data.length; i++) {
    for (var j = data[i].child.length - 1; j >= 0; j--) {
        if (data[i].child[j].boxId == removedId) 
            data[i].child.splice(j, 1);
    }
}
console.log(data);

1 个答案:

答案 0 :(得分:0)

您已使用ajax在user_online.php中执行某项操作,因此需要在.load()中再次加载数据。所以

改变这一点,

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

如果您在user_online.php中仅使用php,请确保echo值。