Menu Close
    Searching for an experienced eCommerce & Marketplace Development Company ?

    Ajax Call from Plugins and Modules In Joomla


    Ajax makes it possible to create websites that are dynamic and fast.
    We can use Ajax to refresh a specific section of a page without reloading all the content or to validate single element without submitting the whole form.

    While developing an extension for Joomla we may encounter a task which requires jQuery Ajax call it may be for the dynamically changing content of an element or to get data based on user input or to perform some operation in the background.

    If we are developing a component then we do not have any issue as we can make Ajax request to any controller of the component but what if we need to create only a plugin or module we might stuck here.

    As in earlier Joomla version, we need to create our own component if we need Ajax call but Joomla! 3.2 includes an AJAX Interface.

    Basically, com_ajax is a component which serves as an interface for Ajax calls for standalone plugins and modules.

    Some Use Cases

    • First, A module/plugin that retrieves data from an external API
    • Second, A module/plugin that interacts with a component that you did not develop
    • Third, A module/plugin that requires data using Ajax, we can write ajax method in same module/plugin

    How does Ajax Call work for modules and plugins?

    First of all, when making Ajax call from module/plugin URL must be, index.php?option=com_ajax.

    Other Parameters:

    Required –




    Optional –

    method=[method name] defaults is get if not provided.

    A request to ?option=com_ajax&module=search would call mod_search with results returned in the default format. Similarly ?option=com_ajax&plugin=search&format=json would trigger the onAjaxSearch with results returned in JSON.

    com_ajax for Modules

    For using Ajax call in Modules some requirements are:

    1. A method must be defined in helper.php
    2. The request must include a module variable in the URL.Example:module=search for mod_search
    3. Optionally method variable can be used in the URL to replace default get method. Example: method=myFunction this will trigger myFunctionAjax

    Example Request

        url: 'index.php?option=com_ajax&module=search&method=getData',
        type: "post",
        success :function(response){

    Above code will trigger method getDataAjax in helper.php of search module.

    public static getDataAjax(){
        //search records
    Note: function must be static otherwise warnings will be thrown.

    com_ajax for Plugins

    For using Ajax call in plugins some requirements are:

    1. The method name must start with onAjax. Example: onAjax[Name]
    2. The request must include a plugin variable in the URL.Example:plugin=getData this will trigger onAjaxgetData
    3. Optionally group variable can be used in the URL to specify plugin group.

    Example Request

     * WKSOCIALMESSAGE -Joomla Social Messaging
     * @category   Plugin
     * @package    Joomla
     * @author     WebKul software private limited 
     * @copyright  2010 WebKul software private limited
     * @license GNU/GPL
     * @version    GIT:1.0
     * @filesource
     * @link       Technical Support:
        url: 'index.php?option=com_ajax&group=system&plugin=connectWksocialTwitterProfile&format=json',
        type: "post",
        success: function(data){
            //handle success
            //handle error

    Above code will trigger method onAjaxConnectWksocialTwitterProfile in the plugin file.

     * [onAjaxConnectTwitterProfile trigger onAjax for login user profile]
     * @since  v1.0
     * @return [string] [content to render ]
    public function onAjaxConnectWksocialTwitterProfile()
       //login user via twitter
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top

    Table of Content

    Hide Index