Ajax for modules

We use ajax for our modules to allow us to update pages without the need to completely reload them. This is especially useful when we need to have pages for the different content types. For example when we display YouTube videos and there are perhaps 100+ videos, we want to display then in pages. This speeds up the page loading which is important for mobile devices.

Ajax is a term for the loading of data without the need to reload the page. When developing Joomla Modules it’s relatively simple to implement. In Joomla 3.2 onward Joomla implemented com_ajax. This is a generic component which allows for the use of Ajax technology.

Although there is lots of information on the web about how to implement this when we started we couldn’t find anywhere that covered all of the pieces that are needed. So this post sets out the parts that are needed and is here for two purposes – to help others and to act as a place that we can return to when we’re developing software!

There are two parts to the Ajax system in a module:

Javascript code in the default.php file

Php code in the helper.php file

The default file makes the request for the information and the helper file gets the information.

Typical code in the default file would be:

Leave a Reply

Your email address will not be published. Required fields are marked *