PDA

View Full Version : Refreshing posts of a forum via ajax?



Vernier
08-15-2012, 11:00 AM
Hi guys,

How could I refresh all the posts of a forum every X seconds using AJAX so that the user doesn't have to reload the page?

Cheers :)

djr33
08-15-2012, 11:06 AM
In what sense?

AJAX allows you to replace content on a page with new content from a server. That's the (relatively) easy part, or at least it's straightforward.

But to do this you'll also need a serverside language (probably PHP?) that will load the posts themselves. Do you have this set up? What forum software are you using?

If this is not your own design (a forum made from software you downloaded) then the best option would be to check for a plugin/add-on/extension/mod that allows you to do this. Maybe someone else has already done the work for you.

If this is your own design, then you should be able to easily do the PHP part and you'll just need to plug in the AJAX for it.

Vernier
08-15-2012, 11:10 AM
Thanks for the reply

I'm actually attempting to make a modification myself.

The forum software is MyBB.

Thanks :)

djr33
08-15-2012, 11:17 AM
An AJAX setup requires two parts:

1. An AJAX script (Javascript) that will replace part of the page with new content from a certain URL on the server.

2. A PHP script that will generate the content when that URL is loaded. Note that this content should not be a full HTML page, but rather just the local HTML needed for that section of the page. For example, it might be <div>...</div> or <p>...</p>, but in almost all cases not <html>...</html>.

There are many AJAX scripts around that you can use for part (1). The more specific part will be part (2). For that, you'll need to figure out how to deal with MyBB's post system. If MyBB has an API, that might be very helpful.

Also, I'm still unclear about how you'd expect to refresh the posts without confusing the user, but if you can post more about that, maybe someone will have an idea.