Best practices to add AJAX to my admin component

Skip to first unread message


Jul 29, 2022, 9:53:15 AMJul 29
to Joomla! General Development
Hi! reading and wandering around docs I found that I can support AJAX requests in my administrator component in a controller task or in a JsonView and even found that some components have an AjaxController like com_menus (which I don't know what exactly does that AjaxController thing).

¿Which is the right place form my admin component to support AJAX requests? My use case is:

The user tries to send a message to a group of recipients (like the admin user component mail function, but not using email) and I need to show the sending progress to the user . In the sending process, my component need to send the messages in chunks of 100 recipients each time, so for that, I need to send an AJAX request for each chunk, until all recipients chunks are done sending.

But where?
  • In my component ...\Administrator\Controller\SendController send() method?
  • Or to my component  ...\Administrator\View\Send\JsonView display($tpl = null) method?
  • Or somehow hit some method in my component ...\Administrator\Controller\AjaxController ?

I want to use AJAX because after the sending process starts, I want to be able to tell the user how the sending is doing and also avoid PHP max execution time limits.

Thanks in advise!


Jul 30, 2022, 8:47:04 AMJul 30
to Joomla! General Development
Found my answer diggin in the ApplicationController->sendtestmail() of the com_config component.

The sendtestmail member function uses JsonResponse along with the JS class JoomlaFieldSendTestMail in media/system/js/fields/joomla-field-send-test-mail.js

I think if this so common test email utility is coded this way in the Joomla core, it should be the best practice.

Thanks anyway
Reply all
Reply to author
0 new messages