Jump to content

Autorefresh on submit


Zie
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...