Forum Moderators: coopster
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
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.phpif([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
> 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!
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=cewhat?
Andrew
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
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