跳至内容

欢迎!

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.

此问题已终结
作为版主,您可以批准或拒绝该答案。
接受 拒绝
80 查看

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

形象
丢弃

您的回复

请大家尽量给个实质性的回答。如果您想回答这个问题或发表评论,只需 使用评论工具。请记住,您可以随时修改您的答案。 - 不用重复回答同样的问题。另外,请不要忘记投票 - 它确实有助于选择最好的问题和答案!

相关帖文 回复 查看 活动
0
3月 25
72
0
2月 25
74
0
2月 25
114
0
2月 25
111
0
3月 24
84