如何正确编码Joomla MVC组件以执行jQuery AJAX GETS/POSTS? [英] How to correctly code a Joomla MVC component to perform jQuery AJAX GETS/POSTS?

查看:90
本文介绍了如何正确编码Joomla MVC组件以执行jQuery AJAX GETS/POSTS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有了这个壮观的Joomla组件,完成后将带来世界和平,并解决世界饥饿.我要做的就是合并通过jquery .ajax调用调用的代码.我目前将它们放置在外部位置,以便AJAX调用可以到达它们,但不清楚如何正确地将它们放置在Joomla Component结构中.

So, I've got this spectacular Joomla component that when finished, will bring world peace, and solve world hunger. All I have to do is incorporate the code that gets called via the jquery .ajax calls. I currently have them in an external location so that the AJAX calls can get to them, but am not clear how to correctly place them in the Joomla Component structure.

我已经进行了研究,相信我,但是只发现了很多关于您可以尝试这个或那个尝试"的讨论.大概是因为Joomla依赖于mootools,所以Jquery通常不在讨论之列,但是我们内部拥有这个很棒的jQuery例程库,我想使用正确的方式.

I've done the research, trust me, but have only found a lot of discussion about "you could try this, or that". Presumably it's because Joomla relies on mootools, so Jquery is generally out of the discussions, but we have this great library of jQuery routines in-house that I'd like to leverage the right way.

在我看来,必须为每个调用创建一个视图,这似乎需要很多不必要的工作/开销. (就像要求飞行员与乘客一起办理登机手续一样).在我看来,这也不应该那么困难,所以我对我所缺少的东西或为什么没有一个直接的答案感到困惑.

It seems to me that a view has to be created for each call, which seems like a lot of unnecessary work/overhead to accomplish it. (Like asking the pilot to check in to his flight with the passengers). It also seems to me that it shouldn't be this difficult, so am confused about what I'm missing, or why there doesn't appear to be a straight answer.

更新解决方案 接受了Soren的回答,因为它可以直接回答问题,尽管我没有指定Joomla 1.5,但我能够迅速使他的回答适应工作.

UPDATE WITH SOLUTION Accepted answer from Soren because it answers the question directly, though I hadn't specified Joomla 1.5, I was able to quickly adapt his answer to work.

对Greg P的荣誉称赞-他的回答开辟了世界的其他可能性,而我并没有考虑这些其他可能性来快速解决我所遇到的其他项目/挑战.

Honorable mention to Greg P though - his answer opened up a world of other possibilities that i hadn't considered for quick solutions to other projects/challenges that I have.

这是我能够使用AJAX从我的组件成功调用 的URL,以及我添加的使其起作用的内容.

Here's the url I was able to successfully call from my component to my component using AJAX, and what I added to make it work.

index.php?option=com_mycomponent&format=raw&controller=ajax.raw&task=myfunction

components \ com_mycomponent \ controllers \ ajaxraw.php

<?php
    defined('_JEXEC') or die( 'Restricted access' );
    jimport('joomla.application.component.controller');
    class MycomponentControllerAjaxraw extends JController
    {
        function myfunction()
        {
            echo json_encode("SomethingOrOther");
        }
    }
?>

推荐答案

您应该对

index.php?option=com_yourcomponent&task=ajax.function_name&format=raw

然后,您需要创建一个名为ajax.raw.php的新控制器,并在其中编写名称与URL中的"function_name"相匹配的函数,并且这些函数将在调用URL时执行.

You then need to make a new controller called ajax.raw.php and inside that you write functions with names that matches the "function_name" in the URL and they will be executed upon calling the URL.

您可以在其中使用$ this-> getModel();模型.和视图等,甚至在需要时也可以偷懒地将逻辑直接放在控制器中.

From within those you can use models $this->getModel(); and views etc. when needed, or even be lazy and put your logic directly in the controller.

如果您没有组件,请尝试 Joomla组件创建者

If you do not have a component then give the Joomla Component Creator a try

这篇关于如何正确编码Joomla MVC组件以执行jQuery AJAX GETS/POSTS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆