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.

1 Answer 1

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

2
  • thank you. It helped but is there any other way to get this done without com_ajax ? Commented Jan 23, 2015 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
    Commented Jan 23, 2015 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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