我制作了一个小脚本,将页面加载到另一个页面的div中,每隔5秒刷新一次。
页面按预期加载,但间隔似乎不起作用。
我已经搜索了一个解决方案,但所有线程都说我的代码应该像那样工作。所以我决定在这里发布完整的代码。
JQuery(和AJAX):
<script>
function load(){
$('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () {
$(this).unwrap();
});
}
load(); // run it on pageload
setInterval(function(){
load() // this should run every 5 seconds
}, 5000);
</script>
chatlogframe.php文件包含SQL Select查询。每次执行scipt时都应重新加载数据。
更新:
我在Chrome控制台中查看了Uncaught TypeError: $(...).unwrap is not a function
我不认为这个功能是错误的,但也许会有所帮助。
更新2:
继承人html div:
<div id='chatload'></div>
答案 0 :(得分:0)
有效。可能存在$('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () {
$(this).unwrap();
});
.unwrap()可能是问题,但要隔离您需要发布示例HTML容器。
function load() {
console.log("Do something");
$('#chatload').load('https://jsonplaceholder.typicode.com/posts/1', function() {
$(this).unwrap();
});
}
load(); // run it on pageload
setInterval(function() {
load() // this should run every 5 seconds
}, 5000);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="chatload"></div>
&#13;