Development Wiki

Using AJAX

From phpBB Development Wiki

Revision as of 19:58, 19 November 2011 by Callumacrae (Talk | contribs)

phpBB contains a set of functions to make it very easy to have links use AJAX. There are three cases:

Markup changes are not required

When markup changes are not required, it is very easy to AJAXify them. You just need to add the ajax data attribute:

<a href="/link.php?id=4" data-ajax="true">link</a>

Changes in markup are required

To do this, you would use callbacks. You can define your own callbacks using phpbb.add_ajax_callback:

    phpbb.add_ajax_callback('link_test', function() {

<a href="/link.php?id=4" data-ajax="link_test">link</a>

Changes in markup are required and not all information is present

This is trickier. There are two solutions: either you get the information from the server in another AJAX call, or you refresh the page. To refresh the page, you can use the following code:

<a href="/link.php?id=4" data-ajax="link_test" data-refresh="true">link</a>