Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to hit ajax in joomla module ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    Hello Readers,

    Step 1 : First we write the ajax code in default.php file inside module (Ex: mod_mymodule) tmpl/default.php folder.
     
     Code Example :

    $("#id").change(function()
    {
    var id=$(this).val();
    
        $.ajax
        ({
        type: "POST",
        url: "<?php echo JRoute::_('index.php?option=com_ajax&module=my_module&method=getdata&format=raw')?>",
        data: {'id':id}
            success: function(res)
            {
            alert(res);
            } 
        });
    });

    Here,

    1. option=com_ajax
    2. [module|plugin]=name
    3. format=[json|debug|raw]

    In the above code, use the option = com_ajax, name of the module and it's format in raw|json|debug form.

    Step 2 : helper file in joomla module (mod_mymodule) where we write the getdata method or function to post the ajax request.

    Code Example:

    public static function getdataAjax()
    {
        $id=JRequest::getVar('id');
    
        //databse query
    }
    

    In the above code, write the getdata method or function as a getdataAjax() (beacuse all method's must end in Ajax if we use com_ajax as a option in Joomla).

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: