Joomla 3.x has a new component called com_ajax. Which is a thin, extensible component used as a starting point for HTTP requests from modules and plugins.
A few examples of how to use it:
A module that pulls data from an external API
A module that uses the resources of a third-party component
A plugin that implements the API as a functionality on your site
This is by no means the full list of possibilities that com_ajax offers to developers.
Anatomy of Ajax Requests
Required:
option=com_ajax
[module|plugin]=name
Optional:
format=[json|debug] – defaults to raw if not specified
method=[custom fragment] – get by default if not specified.
Browse
All queries start with ?option=com_ajax – a reference to the component. The extension type and name must also be specified.
Additional variables and values used by your extension can also be included in the URL. For example, a request for ?option=com_ajax&module=session, where mod_session is called, with data returned in the default format. In contrast, ?option=com_ajax&plugin=session&format=json would call onAjaxSession and return the result in JSON format.
For modules
Module support is provided by calling a method in the module’s helper.php file.
The module request must include the module variable in the URL, paired with the module name (module=session for mod_session).
This value is also used:
As the name of the directory to check the helper file, e.g. /modules/mod_session/helper.php
As class name to call, for example modSessionHelper
The request can also contain an optional method parameter. The variable can be included to override the default method (get).
NOTE: All methods must end with Ajax. For example: method=mySuperAwesomeMethodToTrigger should be named mySuperAwesomeMethodToTriggerAjax
Ajax-Session-Module is an example module that demonstrates this functionality.
For plugins.
Plugins are supported by calling the plugin event onAjax[Name].
The module request must include the plugin variable in the URL, paired with the module name (plugin=session for onAjaxSession).
This value is also used to:
Passing the name of the plugin for the subsequent plgAjax[Name] conversion
Passing the name of the plugin function for the subsequent onAjax[Name] conversion
Ajax-Latest-Articles is an example plugin that demonstrates this functionality.
The format of the returned data is
format=[json|debug] is an optional argument that defines the format of the result:
json for JSON format
debug for human-readable output