Joomla how to make an ajax call to an helper.php module

心不动则不痛 提交于 2019-12-31 04:12:12

问题


I create a module, not a component, a module because it should appears a number of times, on a number of pages in various positions I follow basic module creation

In default.php I would like to make a ajax call to helper to refresh data, something like that :

$.ajax({ url: '/index.php?option=mod_doodlike&format=raw&tmpl=component, 

all other parameters are in post

Is it possible ? what is the exact URL ? what should I put in helper.php (public function , class myclass extends JController) or in mod_module.php : jimport('joomla.application.component.controller');

or definitely it's a component I need to create ?


回答1:


so after some ggsearch, I succeeded thanks to this post

you have to call itself, best way to do is to use (in default.php):

 'url: "<?php echo JURI::getInstance() ?>",'

Then is mod_yourmodule.php intercept get or post "query" with JRequest::getVar because "$_POST['xxx']" does not work

 '$task = JRequest::getVar('task'); '
 'if($task == ....... '
 'and call the helper modyourmoduleHelper::youfuncion'

In helper, as you don't need all layouts I sent an echo of funcion returned value between “<”reply“>” tags and stoped joomla with jexit()

The reply will be the default.php + the echo easily parsed with :

 'var re = /<reply>(.*)<\/reply>/;'
 'var result = re.exec(T_output);       '       
 'if(result[1] != ''){ Displayfunction($.parseJSON(result[1]));}'

... finished




回答2:


No, you can't call a module URL as modules don't use them.

Your best bet would be to download and install the brand new com_ajax component that acts as an entry point for Ajax functionality. It's available for Joomla 1.5, 2,5 and 3.x, so whichever version you need, don't forget to select that branch first:

https://github.com/betweenbrain-llc/Joomla-Ajax-Interface

Hope this helps



来源:https://stackoverflow.com/questions/19332883/joomla-how-to-make-an-ajax-call-to-an-helper-php-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!