PHP / Joomla

编程入门 行业动态 更新时间:2024-10-26 08:31:20
PHP / Joomla - 从Joomla MVC控制器向hQuery AJAX发送html输出(PHP/Joomla - Sending html output to a jQuery AJAX from a Joomla MVC controller)

我正在尝试在Joomla组件中构建我的第一个jSON表单提交。

从Joomla控制器发送HTML响应有什么特殊的编码或条件吗?

我正在使用2.5 Joomla MVC。 以下是一些测试/观察 -

1)表单提交和响应已经单独测试,并按预期工作。 我有一个单独的PHP文件,提交给服务器端PHP文件,该文件接受jSON数据并发送HTML响应,客户端从响应中正确更新。

2)我在Joomla组件中提交了一份工作表单。 它是一个标准的客户端表单提交,提交给服务器端控制器,屏幕相应地从controller.php文件中的脚本刷新。

3)当我添加jQuery / AJAX表单提交($ .post)时,数据被添加到后端的数据库中,客户端javascript控制台显示jQuery脚本正在运行完成HOWEVER -

我没有收到来自我的控制器的echo'd输出(来自php的简单echo脚本 - > echo'这是一个测试';)

当我用硬编码字符串(而不是AJAX数据结果输出)替换输出的字符串时,客户端按预期更新。 当我用[data]替换硬编码的字符串时,它不起作用。 作为一个额外的测试,我只是回显一个简单的字符串,以便测试控制器,简单的字符串不返回值。

结论 - jQuery / AJAX正在运行但PHP控制器却没有。

I am trying to build my first jSON form submission within a Joomla component.

Is there any special coding or conditions for sending an HTML response from a Joomla controller?

I am using the the 2.5 Joomla MVC. Here are some tests/observations -

1) The form submission and response has been tested separately in isolation and works as expected. I have a separarate PHP file that is submitted to a server side PHP file that accepts the jSON data and sends an HTML response and the client updates correctly from the response.

2) I have a working form submission in my Joomla component. It is a standard client side form submission, submitted to a server side controller and the screen refreshes accordingly from the script in the controller.php file.

3) When I add the jQuery/AJAX form submission ($.post) the data gets added to the database on the backend and the client side javascript console shows that the jQuery script is running to completion HOWEVER -

I am not receiving the echo'd output from my controller (simple echo script from php -> echo 'this is a test';)

When I replace the string that is outputted with a hardcoded string (and not the AJAX data result output) the client updates as expected. When I replace the hardcoded string with [data] it does not work. As an additional test, I am simply echoing out a simple string so as to test the controller and the simple string is not returning value.

Conclusion - jQuery/AJAX is working but PHP controller is not.

最满意答案

它应该足够添加&format = raw到url,这将指示Joomla! 传递组件输出而不是在其周围添加整个模板/页面/模块。

然而,虽然die()不好,但只需在控制器中调用exit就可以实现相同的效果。 有时,当您启用SEF并且基于参数数量的router.php解析器时,这可能是最佳选择。

it should be sufficient to add &format=raw to the url, that will instruct Joomla! to pass through the component output and not add the whole template/page/modules around it.

However while die() is not nice, simply calling exit in the controller will achieve just the same. Sometimes, when you have SEF enabled and a router.php parser based on the number of parameters this can be the best option.

更多推荐

本文发布于:2023-07-22 20:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1223304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   Joomla

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!