gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:44:25 25 4
gpt4 key购买 nike

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

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

假设我有这个脚本。如果 user_online 是我放入的文件,我该如何让它工作(也就是说,我怎样才能让这个脚本在内部工作——在一个与 url 名称相同的 php 文件中)

基本上我想将与上面相同的内容应用到另一个页面,使其自动显示结果而无需重新加载:

<?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的一部分

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

最佳答案

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

改变这个,

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

如果您在 user_online.php 中仅使用 php,请确保您回显这些值。

关于javascript - 在同一个 php 文件中使用 js 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com