Using Joomla Ajax Interface: Difference between revisions
From Joomla! Documentation
No edit summary |
Marked this version for translation |
||
| Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
<noinclude>{{version/tutor|3.2}}</noinclude> | <noinclude>{{version/tutor|3.2}}</noinclude> | ||
<translate>==What is The Joomla Ajax Interface (com_ajax)==</translate> | <translate>==What is The Joomla Ajax Interface (com_ajax)== <!--T:1--></translate> | ||
<translate>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: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. Com_ajax is generally used when you are not the developer of the component that the module or plugin is interacting with.</translate> | |||
<translate>'''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:3--> | ||
'''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>Examples of use cases include, but are not limited to: | <translate><!--T:4--> | ||
Examples of use cases include, but are not limited to: | |||
*A module that retrieves data from an external API | *A module that retrieves data from an external API | ||
*A module that interacts with a component that you did not develop | *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</translate> | *A plugin that implement API like functionality to allow consumption of data from your site</translate> | ||
<translate>==Anatomy of an Ajax Request==</translate> | <translate>==Anatomy of an Ajax Request== <!--T:5--></translate> | ||
<translate>===Required===</translate> | <translate>===Required=== <!--T:6--></translate> | ||
*<code>option=com_ajax</code> | *<code>option=com_ajax</code> | ||
| Line 19: | Line 22: | ||
*<code>format=[json|debug|raw]</code> | *<code>format=[json|debug|raw]</code> | ||
<translate>===Optional===</translate> | <translate>===Optional=== <!--T:7--></translate> | ||
*<code>method=[custom fragment]</code> <translate>defaults to <code>get</code> if omitted.</translate> | *<code>method=[custom fragment]</code> <translate><!--T:8--> | ||
defaults to <code>get</code> if omitted.</translate> | |||
<translate>===Overview===</translate> | <translate>===Overview=== <!--T:9--></translate> | ||
<translate>All requests begin with <code>?option=com_ajax</code>, which calls this extension, and must indicate the type of extension to call, and the data format to be returned. | <translate><!--T:10--> | ||
All requests begin with <code>?option=com_ajax</code>, which calls this extension, and must indicate the type of extension to call, and the data format to be returned. | |||
<!--T:11--> | |||
Additional variables and values used by your extension may also be included in the URL.</translate> | Additional variables and values used by your extension may also be included in the URL.</translate> | ||
<translate>For example, a request to <code>?option=com_ajax&module=session</code> would call <code>mod_session</code> with results returned in the default format. In contrast,<code>?option=com_ajax&plugin=session&format=json</code> would trigger the <code>onAjaxSession</code> plugin group with results returned in JSON.</translate> | <translate><!--T:12--> | ||
For example, a request to <code>?option=com_ajax&module=session</code> would call <code>mod_session</code> with results returned in the default format. In contrast,<code>?option=com_ajax&plugin=session&format=json</code> would trigger the <code>onAjaxSession</code> plugin group with results returned in JSON.</translate> | |||
<translate>==Module Support==</translate> | <translate>==Module Support== <!--T:13--></translate> | ||
<translate>===Summary===</translate> | <translate>===Summary=== <!--T:14--></translate> | ||
<translate>Module support is accomplished by calling a method in the module's <code>helper.php</code> file.</translate> | <translate><!--T:15--> | ||
Module support is accomplished by calling a method in the module's <code>helper.php</code> file.</translate> | |||
<translate>===Details===</translate> | <translate>===Details=== <!--T:16--></translate> | ||
<translate>Module requests must include the <code>module</code> variable in the URL, paired with the name of the module (i.e. <code>module=session</code> for <code>mod_session</code>).</translate> | <translate><!--T:17--> | ||
Module requests must include the <code>module</code> variable in the URL, paired with the name of the module (i.e. <code>module=session</code> for <code>mod_session</code>).</translate> | |||
<translate>This value is also used for: | <translate><!--T:18--> | ||
This value is also used for: | |||
<!--T:19--> | |||
*The name of the directory to check for the helper file, e.g. <code>/modules/mod_session/helper.php</code> | *The name of the directory to check for the helper file, e.g. <code>/modules/mod_session/helper.php</code> | ||
<!--T:20--> | |||
*The class name to call, e.g. <code>modSessionHelper</code></translate> | *The class name to call, e.g. <code>modSessionHelper</code></translate> | ||
<translate>Optionally, the <code>method</code> variable may be included to override the default method prefix of <code>get</code>.</translate> | <translate><!--T:21--> | ||
Optionally, the <code>method</code> variable may be included to override the default method prefix of <code>get</code>.</translate> | |||
:<translate>'''NOTE''': All methods must end in <code>Ajax</code>. For example:</translate> | :<translate><!--T:22--> | ||
:<code>method=mySuperAwesomeMethodToTrigger</code> <translate>will call</translate> <code>mySuperAwesomeMethodToTriggerAjax</code> | '''NOTE''': All methods must end in <code>Ajax</code>. For example:</translate> | ||
:<code>method=mySuperAwesomeMethodToTrigger</code> <translate><!--T:23--> | |||
will call</translate> <code>mySuperAwesomeMethodToTriggerAjax</code> | |||
<translate>The [https://github.com/Joomla-Ajax-Interface/Ajax-Session-Module Ajax Session Module] is an example module that demonstrates this functionality.</translate> | <translate><!--T:24--> | ||
The [https://github.com/Joomla-Ajax-Interface/Ajax-Session-Module Ajax Session Module] is an example module that demonstrates this functionality.</translate> | |||
<translate>==Plugin Response==</translate> | <translate>==Plugin Response== <!--T:25--></translate> | ||
<translate>===Summary=== | <translate>===Summary=== <!--T:26--> | ||
<!--T:27--> | |||
Plugin support is accomplished by triggering the <code>onAjax[Name]</code> plugin event.</translate> | Plugin support is accomplished by triggering the <code>onAjax[Name]</code> plugin event.</translate> | ||
<translate>===Details=== | <translate>===Details=== <!--T:28--> | ||
<!--T:29--> | |||
Plugin requests must include the <code>plugin</code> variable in the URL, paired with the name of the plugin event, e.g. <code>plugin=session</code> for <code>onAjaxSession</code>.</translate> | Plugin requests must include the <code>plugin</code> variable in the URL, paired with the name of the plugin event, e.g. <code>plugin=session</code> for <code>onAjaxSession</code>.</translate> | ||
<translate>This value is also used for: | <translate><!--T:30--> | ||
This value is also used for: | |||
<!--T:31--> | |||
*The plugin class name following the <code>plgAjax[Name]</code> convention. | *The plugin class name following the <code>plgAjax[Name]</code> convention. | ||
*The plugin function name following the <code>onAjax[Name]</code> convention. | *The plugin function name following the <code>onAjax[Name]</code> convention. | ||
<!--T:32--> | |||
The [https://github.com/Joomla-Ajax-Interface/Ajax-Latest-Articles Ajax Latest Articles plugin] is an example plugin that demonstrates this functionality.</translate> | The [https://github.com/Joomla-Ajax-Interface/Ajax-Latest-Articles Ajax Latest Articles plugin] is an example plugin that demonstrates this functionality.</translate> | ||
<translate>==Response Format==</translate> | <translate>==Response Format== <!--T:33--></translate> | ||
<translate><code>format=[json|debug]</code> is an optional argument for the results format: | <translate><!--T:34--> | ||
<code>format=[json|debug]</code> is an optional argument for the results format: | |||
<!--T:35--> | |||
*<code>json</code> for JSON format | *<code>json</code> for JSON format | ||
*<code>debug</code> for human-readable output of the results.</translate> | *<code>debug</code> for human-readable output of the results.</translate> | ||
<translate>[[Category:AJAX]] | <translate><!--T:36--> | ||
[[Category:AJAX]] | |||
[[Category:JavaScript]] | [[Category:JavaScript]] | ||
[[Category:Development]]</translate> | [[Category:Development]]</translate> | ||
Revision as of 21:05, 9 November 2014
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]=nameformat=[json|debug|raw]
Optional
method=[custom fragment]defaults togetif 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=mySuperAwesomeMethodToTriggerwill callmySuperAwesomeMethodToTriggerAjax
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 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:
jsonfor JSON formatdebugfor human-readable output of the results.