Sofian Hitali
Sofian Hitali

Reputation: 11

joomla 5 - issue on adding ajax on module using Ajax-com

i am trying to add auto load contents to my existing module by using joomla ajax-com . the module display videos on the page , it is not has pagination .

i created a helper file in the root of the module like this : mod_mymodulename/helper.php

i added in the helper.php a function like this : static function getDataAjax() { my code}

i added it in the xml file like this :

<filename>helper.php</filename> 

under <files>

i added in tmpl/default.php js code like this : (this is a part of the code ) on button click

url: 'index.php?option=com_ajax&module=mod_mymodulename&method=getData&format=json',

on the site i get this error message :

the method getDataAjax not found

where is my fault ? why the code cant find the getDataAjax ?

the getDataAjax is there in helper.php .

update :

i noticed that this code is fore joomla 3 ::

<script>
function load_videos() {
let nusers = document.querySelector('.load-more-videos');
Joomla.request({
url: 'index.php?option=com_ajax&module=mymodulename&method=getData&format=json',
method: 'GET',
onSuccess(data) {
const response = JSON.parse(data);
if (response.success) {
nusers.innerHTML = response.data;
} else {
const messages = {"error": [response.message]};
Joomla.renderMessages(messages);
}
},
onError(xhr) {
Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr));
const response = JSON.parse(xhr.response);
Joomla.renderMessages({"error": [response.message]}, undefined, true);
}
});
}
</script>

anybody can address me where can i find the right info about com-ajax for joomla 5 ? 
i searched google , i found only for j3 and j4 .

Upvotes: 1

Views: 56

Answers (0)

Related Questions