elzi
elzi

Reputation: 5672

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?

Upvotes: 0

Views: 1549

Answers (2)

James L.
James L.

Reputation: 4097

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).

Upvotes: 1

SLaks
SLaks

Reputation: 887315

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.

Upvotes: 4

Related Questions