如何从 Joomla 向自己发起 AJAX 调用!模块? [英] How to make AJAX call to myself from Joomla! module?
问题描述
我编写了一个依赖于某些第三方设备(加载、解析和显示)的模块.有时它需要 5 秒才能响应,所以我试图对这部分进行 ajaxify.
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.
我的 Joomla!模块和 AJAX 代码(mootools)都准备好了,但我无法找出访问 Joomla注入"我的模块 php 文件的 URL!(类似于/index.php?option=com_content).我可以硬编码并访问它(/modules/mod_a/xyz.php),但我会遇到不允许直接访问"的情况,这没有问题,但我没有 Joomla!我非常想念的上下文.
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.
感谢您的建议,
问候,
马雷克
推荐答案
我确实编写了最简单的组件(没有 MVC):
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
}
这可以通过 JURI::current()."index.php?option=com_xzy&task=getCurrentTemp" 打印 (heredoc) 到 JS.无法访问模块有点糟糕,但我从架构的角度理解这一点.
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.
这篇关于如何从 Joomla 向自己发起 AJAX 调用!模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!