How to autorefresh only a part of page ?
Posted December 27th 2011, 7:27am
As the title says, how can I autorefresh only a div and not the entire page ?

Thank's
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
How to autorefresh only a part of page ?
Posted December 27th 2011, 12:00pm
You could make an Ajax call to the current page URL for the div you want to refresh and load it into the div you want to refresh.

For example,
$('#DIVtoREFRESH').load('CURRENT URL #DIVtoREFRESH');
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
How to autorefresh only a part of page ?
Posted December 27th 2011, 12:27pm
take a look at many revisions too
http://jsfiddle.net/defencedog/AAMfq/
φ
Posts: 163
Joined: August 5th 2011, 11:00pm
Location: Pakistan
Likes Given: 34
Likes Received: 3
How to autorefresh only a part of page ?
Posted December 27th 2011, 5:22pm
sorry I forgot to mention a thing !

I want autorefresh...

Sorry again !
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Re: How to autorefresh only a part of page ?
Posted December 27th 2011, 6:05pm
Using LGforum's example, auto-refresh would require a timing loop such as:

function refresh() {

    setTimeout("$('#DIVtoREFRESH').load(document.URL+' #DIVtoREFRESH',function(){refresh();})", 30000);
}

refresh();

The above is set to refresh every 30 seconds. It's not the way I would personally do it, but it will get the job done...
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Re: How to autorefresh only a part of page ?
Posted December 28th 2011, 11:24am
I had mentioned it else where but using this is appropriate

function refresh() {

    setInterval("$('#DIVtoREFRESH').load(document.URL+' #DIVtoREFRESH',function(){refresh();})", 30000);
}


setInterval is especially meant for continuously running functions
φ
Posts: 163
Joined: August 5th 2011, 11:00pm
Location: Pakistan
Likes Given: 34
Likes Received: 3
Re: How to autorefresh only a part of page ?
Posted December 28th 2011, 1:47pm
Here is what I tried

<div id="DIVtoREFRESH">

my content
</div>

<script type="text/javascript">
function refresh() {
    setTimeout("$('#DIVtoREFRESH').load('document.URL #DIVtoREFRESH',function(){refresh();})", 3000);
}

refresh();
</script>


that after 3 seconds (I reduced the time) makes the content disappear :(
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
1
#8
Re: How to autorefresh only a part of page ?
Posted December 28th 2011, 3:53pm
changing it to this should work:


<div id="DIVtoREFRESH">
my content
</div>

<script type="text/javascript">
function refresh() {
    setTimeout("$('#DIVtoREFRESH').load(document.URL+' #DIVtoREFRESH',function(){refresh();})", 3000);
}

refresh();
</script>
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
How to autorefresh only a part of page ?
Posted December 29th 2011, 6:57am
Did that work for you ?

It does make the content to dissapear :( :(

I copied and pasted it in a HTML page using header and footer !
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Re: How to autorefresh only a part of page ?
Posted December 29th 2011, 7:30am
Can i see that HTML page?

I suspect the problem will be, that it is loading the actual full div with the same id into the div rather than just the contents of the DIV.

In which case you'd be better doing it like so:


<div id="areaTOrefresh">
<div id="refreshContents">CONTENT</div>
</div>

<script type="text/javascript">
function refresh() {
    setTimeout("$('#areaTOrefresh').load(document.URL+' #refreshContents',function(){refresh();})", 3000);
}

refresh();
</script>


Therefore its bringing the contents through and not the actual same div into the div.
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
How to autorefresh only a part of page ?
Posted December 30th 2011, 3:29am
The same thing for me :( I've sent you the page URL on pm !
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
How to autorefresh only a part of page ?
Posted December 31st 2011, 6:05am
Anything new ?
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
How to autorefresh only a part of page ?
Posted December 31st 2011, 5:10pm
Bump :(
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Topic locked
13 posts

Who is online

Users browsing this forum: No registered users and 1 guest