简体   繁体   中英

JQuery interval isn't working

I've made a small script to load a page into a div of another page, which gets refreshed every 5 seconds.

The page is loaded as expected, but the interval doesn't seem to work.

I already searched for a solution, but all threads are saying that my code should work like that. So I decided to post the full code here.

JQuery (and 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>

The chatlogframe.php file contains a SQL Select query. The data should be reloaded every time the scipt gets executed.

UPDATE:

I checked the Chrome Console where it says Uncaught TypeError: $(...).unwrap is not a function

I don't think that the function is wrong, but maybe it helps.

UPDATE 2:

Heres the html div:

<div id='chatload'></div>

It works. May be there's some issue with your code in $('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () { $(this).unwrap(); });

.unwrap() could be possible issue but to isolate that you would need to post your sample HTML container.

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM