How to make AJAX call to myself from Joomla! module?

邮差的信 提交于 2020-01-03 00:56:06

问题


I wrote a module that is dependent on some third party device (load, parse & display). Sometimes it takes 5 seconds for it to respond so I tried to ajaxify this part.

My Joomla! module is ready as well as code with AJAX (mootools) but I can't figure out the URL to access my module php file "infused" by Joomla! (something like /index.php?option=com_content). I can hardcode and access it (/modules/mod_a/xyz.php) but I will run into "direct access not allowed" which is no trouble, but I don't have the Joomla! context which I pretty much miss.

All I found utilizes components which I would very much like to avoid.

Thanks for suggestions,

Regards,

Marek


回答1:


You cannot access to your module by url. The only way to create very simple component with one model and one view for this purpose. Or you could add one task to one the components installed in your site.




回答2:


I did write the simplest component I could (no MVC):

defined('_JEXEC') or die('Restricted access');
$task = JRequest::getWord('task');
if ($task == "getCurrentTemp") {
 // return temperature
}

This can be printed (heredoc) to JS by JURI::current()."index.php?option=com_xzy&task=getCurrentTemp". Not being able to access module sucks a little bit but I understand that from architectural point of view.



来源:https://stackoverflow.com/questions/6755134/how-to-make-ajax-call-to-myself-from-joomla-module

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