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