使用 Joomla,我如何只调用 php 函数生成的输出进入 AJAX 调用? [英] With Joomla, how do I get into an AJAX call only the output generated by the php function called?

查看:19
本文介绍了使用 Joomla,我如何只调用 php 函数生成的输出进入 AJAX 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 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.

我可以将请求发送到位于 controller.php 文件中的 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是-div id="select-formatocarta"-,你可以看到在select"之前我还有很多其他不需要的东西.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=component 参数的唯一菜单,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.

如何在没有 Joomla 模板的情况下接收唯一的 php 函数输出?如果这是不可能的,我怎样才能从 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.

推荐答案

你需要在你的/components/com_yourcomponent/controllers/文件夹中创建一个名为 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?option=com_name&task=ajax.function_name&format=raw&var=value

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

  • function_name"将在控制器内部执行同名函数.
  • format=raw 告诉 joomla 不要包含模板
  • var=value 代表您想要发送的任何参数,并且可以使用 JRequest::getVar() 检索

这篇关于使用 Joomla,我如何只调用 php 函数生成的输出进入 AJAX 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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