的Joomla如何使一个AJAX调用一个helper.php模块 [英] 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我想作一个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,
所有其他参数都在交
all other parameters are in post
这可能吗?什么是确切的网址是什么?
我应该把在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后,我成功得益于<一个href="http://www.simplifyyourweb.com/index.php/developers-corner/24-hands-on/39-including-jquery-into-a-joomla-module"相对=nofollow>这个帖子
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因为$ _ 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'
在帮手,因为你并不需要所有的布局我给funcion的回声之间的返回值&LT;回复>标签和采空的Joomla与jexit()
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]));}'
...完成
... finished
这篇关于的Joomla如何使一个AJAX调用一个helper.php模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!