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

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

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>
  • 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 '17 at 5:28

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.