4

I have no experience with Ajax and little to no experience with Joomla. I've managed to create my own Joomla modules with no problem. Today I tried to use Ajax in one of my modules but I am getting an error: "Method getAjax does not exist.".

Here is my helper.php

<?php

class ModDisplayVacancies
{
    public static function getAjax()
    {
       return "getAjax return";
    }

....
}

my mod_display_vacancies.php

<?php

// No direct access
defined('_JEXEC') or die;
// Include the syndicate functions only once

$document = JFactory::getDocument();
require_once dirname(__FILE__) . '/helper.php';


$document->addStyleSheet('/Joomla/modules/mod_display_vacancies/css/styles.css');
$document->addScript('/Joomla/modules/mod_display_vacancies/js/custom.js');


$table = ModDisplayVacancies::createTable($params);

require JModuleHelper::getLayoutPath('mod_display_vacancies');

And my JavaScript:

jQuery(document).on('click', 'button[id=vacancies_next]', function(){

    console.log("next");

    var request = {
        'option' : 'com_ajax',
        'module' : 'display_vacancies',
        'data' : 5,
        'format': 'json'
    }

    jQuery.ajax({
        type: 'GET',
        data: request,
        success:function(responce){
            console.log("success");
            console.log(responce);
        },
        error:function(responce){
            console.log("error");
            console.log(responce);
        }
    });  


});

It's pretty strange to me why in the console I'm getting "success" and then an error:

console screenshot

1
  • Your issues may be due to naming conventions - what happens if you rename your helper Class to modDisplayVacanciesHelper or modDisplay_VacanciesHelper?
    – FFrewin
    Oct 9, 2017 at 14:45

1 Answer 1

3

Your Helper Class name should be:

ModDisplayVacanciesHelper

And the Module must be published on all pages, if not you have to add one menu ID in your request where the module is published. Just like this:

&Itemid=<menu id>
1
  • I've changed the name of my helper class to ModDisplayVacanciesHelper and it resolved my problem. But the module is published only on one single page inside my hidden menu ( I have two menus one of which is hidden one). Thanks for your help !
    – VTodorov
    Oct 10, 2017 at 5:28

Your Answer

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

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