Ajax is not available by namespace!
<namespace path="src">Am\Module\Amap</namespace>
...
Joomla.request({
url: "index.php?option=com_ajax&module=amap&method=getReloadLayoutParams&format=json",
method: "POST",
headers: {
"Cache-Control" : "no-cache",
"Content-Type" : "application/json"
},
onBefore: function (xhr){
console.log("onBefore");
},
onSuccess: function (response, xhr){
if (response !== ""){
let res = JSON.parse(response);
console.log(res.message);
}
console.log("onSuccess");
},
onError: function(xhr){
console.log("onError");
},
onComplete: function (xhr){
console.log("onComplete");
}
});
path 'modules/mod_amap/src/Helper/AmapHelper.php'
<?php
namespace Am\Module\AMAP\Site\Helper;
\defined( '_JEXEC' ) or die;
class AmapHelper
{
public static function getReloadLayoutParamsAjax()
{
$html = array();
$html['success'] = true;
$html['message'] = 'Ok';
$html['messages'] = '';
$html['data'] = array();
echo json_encode($html);
exit;
}
}
JSON data
onBefore
File mod_amap/helper.php does not exist. // ??? It doesn't exist anyway
onSuccess
onComplete
Joomla v. 4.1.0-rc4
PHP 7.4.27
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Title |
|
But that's not good, I think.
This is the Joomla 4 way which is not 100% B/C because of namespacing...
Creating a separate file in a module just to be able to use com_ajax is definitely a problem.
I don't understand why when com_ajax knows the exact location and file name of a module class, we have to load that class manually in a separate file.
Also, there is no documentation about this in the com_ajax usage description.
Running into the same issue.
In J4 Module Helper are namespaced and in src directory. com_ajax is apparently not able to load this helper file and then falls back to J3 file locations > 'mod_module'/helper.php which is not correct.
You can try this yourself on a J4 site: [yourdomain/index.php?option=com_ajax&module=articles_news&method=test&format=raw
(note: a Joomla core module!)
which results in:
RuntimeException: The file at mod_articles_news/helper.php does not exist.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-03-29 10:18:52 |
Closed_By | ⇒ | richard67 |
Status | Closed | ⇒ | New |
Closed_Date | 2022-03-29 10:18:52 | ⇒ | |
Closed_By | richard67 | ⇒ |
Labels |
Added:
bug
|
I confirm the problem.
In /components/com_ajax/ajax.php
$moduleInstance = $app->bootModule('mod_' . $module, $app->getName());
no helper class returned for a helper file in a subdirectory /src/Helper.
As a solution can use:
https://github.com/dgrammatiko/invalidate-cache/blob/d19f7f1b6b375dfcc4417d84c8ac3697097a84fd/src/invalidatecache/services/provider.php
But that's not good, I think.