PDA

View Full Version : Update part of a webpage every few seconds using AJAX?



edparry
08 Feb 2011, 02:07 PM
Okay. Basically, I have a website that allows the user to enter in a short message. The message is added to a file using PHP. Another PHP script picks a random message (line) from that file, and displays it on the page. It's a random idea, but I'm using it more so to learn web development more than anything.

I'd like to have the message that appears on the screen change every so often, without the user having to refresh. At the moment, if you refresh the page, you get another random message, but is it possible to have a new message appear after a certain time? If so, how would I implement it?

Thanks in advanced :)

Jason
08 Feb 2011, 03:36 PM
You can use JavaScript's setInterval. This will excecute a code snippet every set amount of time. You can then run an ajax request request to run your php request and insert what it returns.