5

I need to access helper class function through ajax request.

In JS file :-

var sbfootscores = {};

    (function($){
        sbfootscores.getTeams = function(competition_id){
            $.ajax({
                url:'',
                type:"POST",
                data:{com_id:competition_id},
                success: function (data) {
                    console.log(data);
                }
            });
        }
    })(jQuery)

In helper Class:-

public static function getTeams(){
        //i need to access this function 
    }

What url to put in ajax's options url??

Any Help will be appreciated.

2

Assuming your module is utilising the com_ajax component that is included in Joomla 3.2+ then you can use the following:

url: 'index.php?option=com_ajax&module=NAME&method=getTeams&format=json'

Have a look at the Ajax Interface documentation for more information:

https://docs.joomla.org/Using_Joomla_Ajax_Interface

  • thank you. It helped but is there any other way to get this done without com_ajax ? – subashbasnet8 Jan 23 '15 at 9:11
  • Yes, but I would not recommend it. com_ajax is there to make your life much easier. If you need to support older versions of Joomla that don't include the com_ajax component, then you can always display a warning saying the user must download/install it. There is a standalone version of it that's available to install ;) – Lodder Jan 23 '15 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.