Difference between revisions of "Using Joomla Ajax Interface/en"

From Joomla! Documentation

(Importing a new version from external source)
 
(Importing a new version from external source)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude><languages /></noinclude>
 
<noinclude><languages /></noinclude>
<noinclude>{{version/tutor|3.2}}</noinclude>
+
<noinclude>{{Joomla version|version=3.2|time=and after|comment=series}}</noinclude>
 +
{{-}}
 
==What is The Joomla Ajax Interface (com_ajax)==
 
==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.
 
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.
Line 66: Line 67:
 
*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.
 +
*The default plugin group is <code>ajax</code>. You can change it specifying the <code>group</code> request parameter. (From Joomla! 3.4)
  
 
The [https://github.com/Joomla-Ajax-Interface/Ajax-Latest-Articles Ajax Latest Articles plugin] is an example plugin that demonstrates this functionality.
 
The [https://github.com/Joomla-Ajax-Interface/Ajax-Latest-Articles Ajax Latest Articles plugin] is an example plugin that demonstrates this functionality.

Latest revision as of 09:50, 26 May 2015

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎русский • ‎فارسی • ‎中文(台灣)‎
Joomla! 
≥ 3.2
series

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.