Using Joomla Ajax Interface: Difference between revisions
From Joomla! Documentation
Marked this version for translation |
Added deprecation notice and link to Joomla Manual |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Warning|This page has been superseded and is no longer maintained. Please go to [https://manual.joomla.org/docs/general-concepts/javascript/com-ajax/ Joomla Manual ] instead}} | |||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
<noinclude>{{Joomla version|version=3.2|time=and after|comment=<translate><!--T:37--> | <noinclude>{{Joomla version|version=3.2|time=and after|comment=<translate><!--T:37--> | ||
series</translate>}}</noinclude> | series</translate>}}</noinclude> | ||
{{-}} | {{-}} | ||
<translate>==What is The Joomla Ajax Interface (com_ajax)== <!--T:1--></translate> | <translate>==What is The Joomla Ajax Interface (''com_ajax'')== <!--T:1--></translate> | ||
<translate><!--T:2--> | <translate><!--T:2--> | ||
A slim, extensible component to act as an entry point for HTTP requests for stand alone modules and plugins, thus allowing for the potential of Ajax functionality in them. | A slim, extensible component to act as an entry point for HTTP requests for stand alone modules and plugins, thus allowing for the potential of Ajax functionality in them. ''com_ajax ''is generally used when you are not the developer of the component that the module or plugin is interacting with.</translate> | ||
<translate><!--T:3--> | <translate><!--T:3--> | ||
'''NOTE''' | '''NOTE''' If you are a component developer, you do not need to use ''com_ajax'' to implement Ajax functionality in it. You can do so directly in your component.</translate> | ||
<translate><!--T:4--> | <translate><!--T:4--> | ||
Line 20: | Line 22: | ||
<translate>===Required=== <!--T:6--></translate> | <translate>===Required=== <!--T:6--></translate> | ||
* | *''option=com_ajax'' | ||
* | *''[module|plugin]=name'' | ||
* | *''format=[json|debug|raw]'' | ||
<translate>===Optional=== <!--T:7--></translate> | <translate>===Optional=== <!--T:7--></translate> | ||
* | *''method=[custom fragment]'' <translate><!--T:8--> | ||
defaults to | defaults to ''get'' if omitted.</translate> | ||
<translate>===Overview=== <!--T:9--></translate> | <translate>===Overview=== <!--T:9--></translate> | ||
<translate><!--T:10--> | <translate><!--T:10--> | ||
All requests begin with | All requests begin with ''?option=com_ajax'', which calls this extension, and must indicate the type of extension to call, and the data format to be returned. | ||
<!--T:11--> | <!--T:11--> | ||
Line 36: | Line 38: | ||
<translate><!--T:12--> | <translate><!--T:12--> | ||
For example, a request to | For example, a request to ''?option=com_ajax&module=session'' would call ''mod_session'' with results returned in the default format. In contrast,''?option=com_ajax&plugin=session&format=json'' would trigger the ''onAjaxSession'' plugin group with results returned in JSON.</translate> | ||
<translate>==Module Support== <!--T:13--></translate> | <translate>==Module Support== <!--T:13--></translate> | ||
Line 43: | Line 45: | ||
<translate><!--T:15--> | <translate><!--T:15--> | ||
Module support is accomplished by calling a method in the module's | Module support is accomplished by calling a method in the module's ''helper.php'' file.</translate> | ||
<translate>===Details=== <!--T:16--></translate> | <translate>===Details=== <!--T:16--></translate> | ||
<translate><!--T:17--> | <translate><!--T:17--> | ||
Module requests must include the | Module requests must include the ''module'' variable in the URL, paired with the name of the module (i.e. ''module=session'' for ''mod_session'').</translate> | ||
<translate><!--T:18--> | <translate><!--T:18--> | ||
Line 54: | Line 56: | ||
<!--T:19--> | <!--T:19--> | ||
*The name of the directory to check for the helper file, e.g. | *The name of the directory to check for the helper file, e.g. ''/modules/mod_session/helper.php'' | ||
<!--T:20--> | <!--T:20--> | ||
*The class name to call, e.g. | *The class name to call, e.g. ''modSessionHelper''</translate> | ||
<translate><!--T:21--> | <translate><!--T:21--> | ||
Optionally, the | Optionally, the ''method'' variable may be included to override the default method prefix of ''get''.</translate> | ||
:<translate><!--T:22--> | :<translate><!--T:22--> | ||
'''NOTE''' | '''NOTE''' All methods must end in ''Ajax''. For example:</translate> | ||
: | :''method=mySuperAwesomeMethodToTrigger'' <translate><!--T:23--> | ||
will call</translate> | will call</translate> ''mySuperAwesomeMethodToTriggerAjax'' | ||
<translate><!--T:24--> | <translate><!--T:24--> | ||
Line 75: | Line 77: | ||
<!--T:27--> | <!--T:27--> | ||
Plugin support is accomplished by triggering the | Plugin support is accomplished by triggering the ''onAjax[Name]'' plugin event.</translate> | ||
<translate>===Details=== <!--T:28--> | <translate>===Details=== <!--T:28--> | ||
<!--T:29--> | <!--T:29--> | ||
Plugin requests must include the | Plugin requests must include the ''plugin'' variable in the URL, paired with the name of the plugin event, e.g. ''plugin=session'' for ''onAjaxSession''.</translate> | ||
<translate><!--T:30--> | <translate><!--T:30--> | ||
Line 86: | Line 88: | ||
<!--T:31--> | <!--T:31--> | ||
*The plugin class name following the | *The plugin class name following the ''plgAjax[Name]'' convention. | ||
*The plugin function name following the | *The plugin function name following the ''onAjax[Name]'' convention. | ||
*The default plugin group is | *The default plugin group is ''ajax''. You can change it specifying the ''group'' request parameter. (From Joomla! 3.4) | ||
<!--T:32--> | <!--T:32--> | ||
Line 96: | Line 98: | ||
<translate><!--T:34--> | <translate><!--T:34--> | ||
''format=[json|debug]'' is an optional argument for the results format: | |||
<!--T:35--> | <!--T:35--> | ||
* | *''json'' for JSON format | ||
* | *''debug'' for human-readable output of the results.</translate> | ||
<translate><!--T:36--> | <translate><!--T:36--> |
Latest revision as of 10:30, 27 November 2024
This page has been superseded and is no longer maintained. Please go to Joomla Manual instead
What is The Joomla Ajax Interface (com_ajax)
A slim, extensible component to act as an entry point for HTTP requests for stand alone modules and plugins, thus allowing for the potential of Ajax functionality in them. com_ajax is generally used when you are not the developer of the component that the module or plugin is interacting with.
NOTE If you are a component developer, you do not need to use com_ajax to implement Ajax functionality in it. You can do so directly in your component.
Examples of use cases include, but are not limited to:
- A module that retrieves data from an external API
- A module that interacts with a component that you did not develop
- A plugin that implement API like functionality to allow consumption of data from your site
Anatomy of an Ajax Request
Required
- option=com_ajax
- [module|plugin]=name
- format=[json|debug|raw]
Optional
- method=[custom fragment] defaults to get if omitted.
Overview
All requests begin with ?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=session would call mod_session with results returned in the default format. In contrast,?option=com_ajax&plugin=session&format=json would trigger the onAjaxSession plugin group with results returned in JSON.
Module Support
Summary
Module support is accomplished by calling a method in the module's helper.php file.
Details
Module requests must include the module variable in the URL, paired with the name of the module (i.e. module=session for mod_session).
This value is also used for:
- The name of the directory to check for the helper file, e.g. /modules/mod_session/helper.php
- The class name to call, e.g. modSessionHelper
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=mySuperAwesomeMethodToTrigger will call mySuperAwesomeMethodToTriggerAjax
The Ajax Session Module is an example module that demonstrates this functionality.
Plugin Response
Summary
Plugin support is accomplished by triggering the onAjax[Name] plugin event.
Details
Plugin requests must include the plugin variable in the URL, paired with the name of the plugin event, e.g. plugin=session for onAjaxSession.
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.