与Joomla,我如何才能成为一个AJAX调用只能由PHP函数生成的输出叫什么? [英] With Joomla, how do I get into an AJAX call only the output generated by the php function called?

查看:106
本文介绍了与Joomla,我如何才能成为一个AJAX调用只能由PHP函数生成的输出叫什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个Joomla组件。 在前端的观点我有2下拉菜单选择从第一个选项的形式,第二个选项必须相应地改变。 要做到这一点,我使用AJAX。

I'm creating a Joomla component. In a frontend's view I have a form with 2 drop down menus by choosing an option from the 1st, the options of the 2nd must change accordingly. To do so I'm using AJAX.

我可以将请求发送给PHP函数放在Controller.php这样文件和PHP函数内部产生正确的输出。

I can send the request to the php function placed inside the controller.php file and the php function generates the correct output.

的问题是,框架的Joomla把这个输出一个页面内的所有元标记,标题,模板等,因为它应该被显示在浏览器上之前给它回AJAX。 你可以看到从我收到萤火虫截图。 在这里我想提出的下拉菜单中的分区是-div ID =选择 - formatocarta - ,你可以看到,之前中选择我有许多其他有害的东西。 http://img695.imageshack.us/img695/7725/selectp.jpg

The problem is that Joomla framework put this output inside a page with all the meta tags, header, the template and so on as it should be shown on the browser before to give it back to AJAX. You can see a screenshot from firebug of what I receive. The div where I want to put the drop down menu is -div id="select-formatocarta"-, you can see that before the "select" I have many other unwanted things. http://img695.imageshack.us/img695/7725/selectp.jpg

其结果是,在这里我只想把由PHP函数生成的选择菜单中的DIV中,我得到整个页面。即使我可以显示菜单只能从AJAX请求传递TMPL =元件参数,在div高度就像是整个页面里面。

The result is that inside the div where I want to only put the "select" menu generated by the php function, I get whole page. Even if I can show the only menu passing the tmpl=component parameter from the AJAX request, the div height is like the whole page is inside it.

我怎样才能收到唯一的PHP函数的输出,而不Joomla模板? 如果这是不可能的,我怎么可以提取唯一的下拉菜单从responseText的? 我只可以使用JavaScript,我没有原型或jQuery的使用。

How can I receive the only php function's output without the Joomla template? If that's not possible, how can I extract the only drop down menu from the responseText? I can only use javascript, I don't have prototype or jquery available.

推荐答案

您需要创建你的/组件/ com_yourcomponent /控制器/文件夹的子控制器名为ajax.raw.php

You need to create a sub controller in your /components/com_yourcomponent/controllers/ folder called ajax.raw.php

然后,您可以发送Ajax请求,以这样的:

You can then send ajax requests to it like this:

index.php文件选项= com_name和放大器;任务= ajax.function_name和放大器;格式=原和放大器; VAR =值

index.php?option=com_name&task=ajax.function_name&format=raw&var=value

  • 在函数名将在控制器内执行同一名称的功能。
  • 格式=原告诉的Joomla不包括模板
  • 的变种=转口货值为presents任何你想送,并且可以使用JRequest :: getVar检索参数()

这篇关于与Joomla,我如何才能成为一个AJAX调用只能由PHP函数生成的输出叫什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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