【发布时间】:2017-03-09 18:41:36
【问题描述】:
我正在制作一个网页,我想在其中加载 div 标记中的 php 文件的内容。例如,每 5 秒刷新一次 div 内容并加载一个 php 以在我的主页上进行自我更新,而无需重新加载我的主页。
我遇到的问题是,当计时器重新加载 div 内容时,我的主网页在垂直方向上变得越来越长,并且网页速度变慢。
我正在尝试以这种方式加载: 使用的脚本有 php、jquery、html
function Load_external_content(){
$('#chatsidebar').empty();
$('#chatsidebar').load('chatcnew.php');
}
setInterval('Load_external_content()', 5000);
<div class="chat-sidebar" id='chatsidebar'>
<?php include("chatcnew.php"); ?>
</div>
我的 chatcnew.php 文件中的数据在我的 div 中正确加载,但滚动发生在我的主页上,我不确定发生了什么。
【问题讨论】:
-
如果你正在构建一个聊天系统,我强烈建议你使用网络套接字。轮询所做的只是 DDOS 你自己的服务器。
标签: javascript php jquery html css