Skip to Content

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

This question has been flagged
As a moderator, you can either validate or reject this answer.
Accept Reject
45 Views

This is because cron job runs a PHP file, it executes in a command-line environment (CLI) rather than a web server. Then jQuery (or any JavaScript) runs in a browser, so there is no browser to process JavaScript or jQuery.


Normally we call ajax like

But since this file is run by a cron job, the AJAX call will not execute whenever the cron job runs.


So, we need use dispatcher for J3, factory for J3 & J4

Support J3

=====================================================

use Joomla\CMS\Plugin\PluginHelper;


JPluginHelper::importPlugin('ajax');

$dispatcher = JDispatcher::getInstance();

$result = $dispatcher->trigger('onAjaxTesting', array($data));

=======================================================

Support J3 & J4

========================================================

use Joomla\CMS\Plugin\PluginHelper;


PluginHelper::importPlugin('ajax');

$app = Factory::getApplication();

$result = $app->triggerEvent('onAjaxTesting', array($data));

=========================================================

onAjaxTesting = Ur ajax name

$data = what data you want to pass to ajax


Summary:

-jquery or js is running on browser, which is not supported to auto run by cronjob

-Use dispatcher (J3) || factory (J3 & J4) to trigger js when it got cronjob

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Related Posts Replies Views Activity
0
Mar 25
30
0
Feb 25
39
0
Feb 25
70
0
Feb 25
53
0
Mar 24
69