How to make AJAX call to myself from Joomla! modul

2019-06-01 03:33发布

问题:

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.