简体   繁体   中英

Load and reload content from other page

I would like to place content from another php page in my div and reload this every ten seconds. Currently, I use the following code:

<script>
$(document).ready(function(){
setInterval(function(){
$("#screen").load('https://www.url.com/test.php')
}, 10000);
});
</script>

<div id="screen"></div>

That works great, but I need something that loads the content immediately and then reloads every 10 seconds. Does anyone have any idea? Thanks for your help!

This should work:

<script>
$(document).ready(function(){

function update_screen(){
   $("#screen").load('https://www.url.com/test.php');
}

update_screen();
setInterval("update_screen", 10000);

});
</script>

<div id="screen"></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