How to use Joomla Ajax Interface?

Select your language

How to use Joomla Ajax Interface?


In order to use ajax component, you have to make a call to com_ajax, e.g.; index.php?option=com_ajax, which calls this extension, and must indicate the type of extension to call, and the data format to be returned.

Additional variables and values used by your extension may also be included in the URL.

For example, a request to ?option=com_ajax&module=menu would call mod_menu with results returned in the default format. In contrast, index.php?option=com_ajax&plugin=menu&format=json would trigger the onAjaxMenu plugin group with results returned in JSON.

Following are parameters used in URL:

Required parameters:




Optional parameter:

method=[custom fragment] defaults to get if omitted.

Module Support

Module support is accomplished by calling a method in the module's helper.php file.

Now we will add the module variable in the URL which is a must requirement, paired with the name of the module (i.e. module=menu for mod_menu).

This will look for the helper.php file in the following path:

<Site Root>/modules/mod_menu/helper.php

The class name to call, e.g. modMenuHelper

Optionally, the method variable may be included to override the default method prefix of get.

NOTE: All methods must end in Ajax. For example:

method=myMethodToExecute will call myMethodToExecuteAjax

Note that Ajax is added at the end of the method, not in the URL but in the helper.php file method name

Plugin Response

Plugin support is accomplished by triggering the onAjax[Name] plugin event.

Plugin requests must include the plugin variable in the URL, paired with the name of the plugin event, e.g. plugin=menu for onAjaxMenu

This value is also used for:

The plugin class name following the plgAjax[Name] convention.

The plugin function name following the onAjax[Name] convention.

The default plugin group is ajax. You can change it specifying the group request parameter. (From Joomla! 3.4)

The Ajax Latest Articles plugin is an example plugin that demonstrates this functionality.

Response Format

format=[json|debug] is an optional argument for the results format:

json for JSON format

debug for human-readable output of the results.