簡體   English   中英

JQuery間隔不起作用

[英]JQuery interval isn't working

我做了一個小腳本將頁面加載到另一個頁面的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>

有用。 可能是你的代碼在$('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () { $(this).unwrap(); });存在一些問題$('#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); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="chatload"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM