Joomla 如何对 helper.php 模块进行 ajax 调用 [英] Joomla how to make an ajax call to an helper.php module
问题描述
我创建了一个模块,而不是一个组件,一个模块,因为它应该在不同位置的多个页面上出现多次我遵循 基本模块创建
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
在 default.php 中,我想对 helper 进行 ajax 调用以刷新数据,例如:
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,
所有其他参数都在后
有可能吗?确切的网址是什么?我应该在 helper.php(公共函数,类 myclass 扩展 JController)或 mod_module.php 中放什么: jimport('joomla.application.component.controller');
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 ?
推荐答案
所以经过一些 ggsearch,我成功了感谢 这篇文章
so after some ggsearch, I succeeded thanks to this post
你必须调用自己,最好的方法是使用(在default.php中):
you have to call itself, best way to do is to use (in default.php):
'url: "<?php echo JURI::getInstance() ?>",'
然后是 mod_yourmodule.php 用 JRequest::getVar 拦截 get 或 post "query" 因为 "$_POST['xxx']" 不起作用
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'
在助手中,由于您不需要所有布局,我在<"reply>"标签之间发送了函数返回值的回声,并使用 jexit() 停止了 joomla
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()
回复将是 default.php + 很容易解析的回声:
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]));}'
...完成
这篇关于Joomla 如何对 helper.php 模块进行 ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!