phpBB

Development Wiki

Difference between revisions of "Using AJAX"

From phpBB Development Wiki

(Created page with "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, ...")
 
Line 5: Line 5:
 
When markup changes are not required, it is very easy to AJAXify them. You just need to add the ajax data attribute:
 
When markup changes are not required, it is very easy to AJAXify them. You just need to add the ajax data attribute:
  
<code><a href="/link.php?id=4" data-ajax="true">link</a></code>
+
<pre><a href="/link.php?id=4" data-ajax="true">link</a></pre>
  
  
 
==Changes in markup are required==
 
==Changes in markup are required==
  
To do this, you would use callbacks. You can define your own callbacks using phpbb.add_ajax_callback:
+
To do this, you would use callbacks. You can define your own callbacks using <code>phpbb.add_ajax_callback</code>:
  
<code><script>
+
<pre><script>
 
     phpbb.add_ajax_callback('link_test', function() {
 
     phpbb.add_ajax_callback('link_test', function() {
 
         $(this).delete();
 
         $(this).delete();
Line 18: Line 18:
 
</script>
 
</script>
  
<a href="/link.php?id=4" data-ajax="link_test">link</a></code>
+
<a href="/link.php?id=4" data-ajax="link_test">link</a></pre>
  
  
Line 25: Line 25:
 
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:
 
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:
  
<code><a href="/link.php?id=4" data-ajax="link_test" data-refresh="true">link</a></code>
+
<pre><a href="/link.php?id=4" data-ajax="link_test" data-refresh="true">link</a></pre>

Revision as of 19:58, 19 November 2011

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:

<script>
    phpbb.add_ajax_callback('link_test', function() {
        $(this).delete();
    });
</script>

<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>