0

This is my ajax query for calling a task in the controller (it works for Joomla 3 but doesn't work for Joomla 4):

$.ajax({
    type: "POST",
    url: "index.php?option=com_scrib&task=test&format=raw",
    data: { 'forum_Id': forum_Id  },
    success:function(data)
    {
        var opts = $.parseJSON(data);
        $.each(opts, function(i, d) {
            $('#jform_category_id').append('<option value="' + d.id + '">' + d.name + '</option>');
        });
    }
});

The location of the controller file in Joomla 3: components/com_scrib/controller.php

Joomla 4 has a different file structure. I'm not sure if I'm doing it right.

In Joomla 4: components/com_scrib/src/Controller/DisplayController.php

What the correct url should be in Joomla 4?

1
  • Welcome to JSE, waxman. Please take our tour.
    – mickmackusa
    Mar 8 at 22:14
0

You need to use task=controller.action where controller is whichever controller you want to call less 'Controller' (so MythingController.php contains class MythingController and you use mything in the call) and action is the name of the function to call, so I guess that could be 'test' in your case. My calls don't include type: "POST", and I don't remember why.

The format=raw part looks worrying. You should normally include a form token which can be sent either as a get or post variable. And it is often simple to submit a form in which you first set the form task (hidden) field to the value you want.

1
  • Welcome to JSE and thank you for contributing. Please take our tour.
    – mickmackusa
    Mar 13 at 3:52

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.