gpt4 book ai didi

javascript - 一段时间后自动刷新某些部分,无需在 php 中再次加载页面

转载 作者:行者123 更新时间:2023-12-03 08:15:47 25 4
gpt4 key购买 nike

我用 PHP 编写了代码。其中显示了不同用户所做的帖子。我刚刚将该页面包含在另一个页面中,只是为了将其与其他元素一起查看。现在我希望我包含的部分必须在一段时间后自动刷新。我知道可以通过AJAX来实现,但我对此了解不多。下面是 post.php 文件中的代码,我使用 include"post.php"; 将其包含在主页中,现在在主页上我希望下面这段代码的输出在主页上每 30 秒刷新一次页面但不重新加载页面

<?php
$fetchpost=mysqli_query($conn,"select * from post where b_id IN (select u_id from frndlist where b_id='$b_id')");
?><?php
while($fpost=mysqli_fetch_array($fetchpost)){
$author_id=$fpost[0];
$post_id=$fpost[1];
$post_date=$fpost[2];

$inb_namefetch=mysqli_query($conn,"select b_name from ub_per where b_id='$author_id'");/*getting author's name*/
$inb_mailfetch=mysqli_query($conn,"select b_email from ub_per where b_id='$author_id'");/*getting author's email*/
$inb_mailfetched=mysqli_fetch_array($inb_mailfetch,MYSQLI_ASSOC);
foreach($inb_mailfetched as $authormail){
$authormail;
}
$inb_profpicfetch=mysqli_query($conn,"select prof_pic from ub_per where b_id='$author_id'");/*getting author's profile picture*/
$inb_namefetched=mysqli_fetch_array($inb_namefetch,MYSQLI_ASSOC);
$inb_profpicfetched=mysqli_fetch_array($inb_profpicfetch,MYSQLI_ASSOC);
foreach($inb_profpicfetched as $fetchedimage){
$piccheck=$fetchedimage;
}
if(isset($piccheck)){
$authorimage="http://localhost/uploads/".$authormail."/profilepics/".$fetchedimage;

; }else{$authorimage="http://localhost/content/user.jpg";}
foreach($inb_namefetched as $authorl){
$author=ucwords($authorl);
}
if(isset($fpost[3])){
$post_content=$fpost[3];
}
if(isset($fpost[4])){
$post_image=$fpost[3];
}
?><div class="postingdiv">
<table>
<tr class="authortr" ><td class="author"><a id="imlink" href="http://localhost/profile/view_profile.php?id=<?php echo $author_id; ?>"><img class="authorpic" src="<?php echo $authorimage;?>"></a><a id="tlink" href="http://localhost/profile/view_profile.php?id=<?php echo $author_id; ?>"><?php echo $author; ?></a></td></tr>
<tr class="posttr" ><td class="post"><?php if(isset($post_content)){echo $post_content;} if(isset($post_image)){echo "<br><img id='postimg' src='http://localhost/uploads/".$author_mail."/postpics/".$postimage."'>";} ?></td></tr>

</table></div>
<?php include"commenter.php";
?>

<div class="makoment"><form name="mkoment" method="post" action="http://localhost/content/comment/makecomment.php" ><input type="hidden" name="commentere" value="<?php echo $b_id; ?>"><input type="hidden" name="postsid" value="<?php echo $post_id; ?>"> <textarea class="mycommentarea" name="accomment" placeholder="make a comment"></textarea><br><input type="submit" class="commentbutton" value="Comment"></form></div>
<br>
<?php
}
?>

最佳答案

使用jQuery执行此操作的示例:

setInterval(updateFn, 1000 /* or however long you want the interval */);

function updateFn(){
$.post("page.php", function(response){
console.log(response); //handle the data pinged back by the PHP page in the variable 'response'
});
}

引用文献:

关于javascript - 一段时间后自动刷新某些部分,无需在 php 中再次加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33941011/

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