Forum Moderators: coopster

Message Too Old, No Replies

Smart Refresh?

Smart, refresh/reload of the page

         

scriptmasterdel

2:30 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Right, here i go and this isn't my life story ... well almost isn't ;)

I am creating a website with a message-board type thing (known as 'the board') i suppose you could say it is somewhat more like a tagboard/shoutbox and i have a form that is posting to an iframe that holds the posts.

Now ... instead of the user having to reload the page every so often or me putting a meta-refresh or some type of javascript code set to a time for reloding, i would like to know if its possible to get a page to reload via the server and/or on change of the database? (say when a new entry is inserted into the db)

I thought of having another repetative iframe inside my iframe that reloads and if there is a post newer then the last posted then it reloads but i'm looking for suggestions and i don't mind doing the coding.

I hope i have made some sence,
Thank you all for listening ,
Many thanks for your all help in advance :)

Del

Little_G

3:01 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Hi,

You maybe could make use of 'xmlhttprequest'
example:


http_request = new XMLHttpRequest();

http_request.onreadystatechange = function(){
if(http_request.readyState == 4){
if(http_request.status == 200){
if(http_request.responseText.charAt(0) == '1'){
self.location.reload();
}
}
}
};
http_request.open('GET', 'http://www.example.com/reload.php', true);
http_request.send(null);

reading from a PHP page:
example:


<?php
//reload.php

if([forum needs to be updated]){
echo "1";
}
else{
echo "0";
}
?>

If the forum needs to be updated then it prints out '1' when the javascript downloads it and sees the '1' it reloads the page.

Andrew

scriptmasterdel

3:19 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



What a quick responce!

> I Have never used xmlhttprequest before so this will be fun to learn.

> I have a question though regarding 'reload.php' ....


if([forum needs to be updated])
{
echo "1";
}
else
{
echo "0";
}

I need to display the sane cibtebt ibce abd tgeb ibc=ce the page reloads it should auomatically select the new data so why is this needed?

Thanks!

Little_G

3:33 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Hi,

The javascript on the forum page should at intervals query 'reload.php' and if the response is '1' then reload the page. The 'reload.php' page is in place to allow the javascript to tell if new posts have been added to the forum or not, not to actually download those posts. This saves downloading large amounts of data.

ps.

sane cibtebt ibce abd tgeb ibc=ce
what?

Andrew

scriptmasterdel

10:26 am on Apr 20, 2006 (gmt 0)

10+ Year Member



Sorry i may not have explained myself well enough, lets say that i have a forum and i am posting messages every "5" minutes (on the same thread) and beetween then 5 minutes "bob" posts a message, how could i get the page to reload to show that new "post" without having to reload the page manualy or waiting to see it after i have posted my message?

This is so that i am not missing out on any new messages sent.

p.s. i have no idea what that is that i wrote in my last message

Many thanks for your help,
Del

Little_G

2:30 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



Hi,

Unfortunately there is no way of making the server 'signal' the browser to tell it that the page needs to be updated. Something on the page must make a request to the server to check whether or not the page is up-to-date.

Andrew

scriptmasterdel

2:52 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



Thank you,

I will try and get something together.

Maybe if i add a session variable with the most recent posted date / time in the database and an iframe with the newest added (iframe constantly reloads every 5-10secs) and if they are different date/times then the iframe targets a reload to the page ;)

I'l have a bit of fun with it and if it works it works and if it dont then .... it don't.

Thank you ever so much for your time and help,

Del

Little_G

2:56 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



No problem!

Andrew