Jump to content

Autorefresh on submit


Zie

Recommended Posts

I recently made a shout box in PHP and am in the process of adding more features to it. I've seen many shout boxes contain an auto-refresh feature when someone submits a new shout. I would like to make my shout box do this as well. I was told by a few people that other shout boxes do this with a javascript code, can anyone point me in the right direction of where to go, or how to do this? I don't want it to just refresh one person's shout box, I would like it to refresh the shout box on every page.Thanks in advance for any help!

Link to comment
Share on other sites

You can't have a piece of code that will update other browsers. The HTTP protocol works by the client sending the server a request (referred to as a 'pull'), there's no mechanism in place for the server to 'push' data to the clients without the client having asked for it.So what you need to do is have the shoutboxes on all the clients periodically check the server to see if there are new updates. You can use the Javascript setInterval function to do that. Every 5 seconds or so the browser would check back with the server and see if there are new messages that it needs to show. This isn't exactly "real-time" communication, but it's about as close as you can get with HTTP. This is how most Javascript chat applications work.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...