简体   繁体   中英

Refresh DIV contents every x seconds WITHOUT eternal page?

Here's an example:

<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#photos').load('photos.php').fadeIn("slow");
}, 5000); // refresh every 10000 milliseconds
</script>

<div id="photos"></div>

The problem is the complexity of the other javascript on the page isn't really ideally for reloading the div from an external page. If it's the only way, I'll backtrack and work that out... I was just wondering if it's possible to refresh the div contents from the page itself?

You can read the whole page, then extract the element you're looking for:

$('#photos').load('YourPage.php#photos');

The server will still send the entire page to the client.

function refreshDiv(){
    $('#photos').load('photos.php').fadeIn("slow");
    setTimeout("do_again()", 5000)
}

function do_again(){
    refreshDiv();
}

That would keep loading your jQuery every 5 seconds (5000ms).

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