gpt4 book ai didi

javascript - Jquery页面重新加载错误

转载 作者:行者123 更新时间:2023-11-28 08:08:03 24 4
gpt4 key购买 nike

我正在开发一个消息 PHP 脚本。为了查看用户的消息,我正在尝试重新加载 DIV,以便我应该是实时的。我有两页,第一页显示新消息的数量:

 <?php 
include ('config.php')
?>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script>
var auto_refresh = setInterval(function () {
$('#xxxx').fadeOut('slow', function() {
$(this).load('message.php', function() {
$(this).fadeIn('slow');
});
});
}, 40000);

</script>

<div id="xxxx"><?php include ('yahu.php') ?></div>

其他页面显示重新加载结果:

<?php
include ('config.php');
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
if ($nb_new_pm == 0)
{
}
else
{
?>
<font color="black">You have got <?php echo $nb_new_pm; ?> new message&#40;s&#41;.</font>
<?php
}
?>

首先,它的效果非常好。但是当页面重新加载时,它只显示
的值“nb_new_pm”,它还将其颜色更改为白色。请帮助我!!!!

最佳答案

这里有一些事情让人尖叫。

  1. 您需要考虑使用 PDO,而不是您正在进行的 MySQL 调用。
  2. 查看客户端 JQuery 可以输出的返回 JSON 对象。
  3. 为了扩展第二点,为什么不尝试显示实际的消息呢?而不是计数。
  4. 可以为此研究类似网络套接字的东西。
  5. 最后,如果您不沉迷于 PHP,可以选择 Socket.io。

希望这能有所帮助,祝你好运!

关于javascript - Jquery页面重新加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24594500/

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