douxing1969 2013-04-25 19:32
浏览 66
已采纳

PHP / Joomla - 从Joomla MVC控制器向hQuery AJAX发送html输出

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.

  • 写回答

1条回答 默认 最新

  • dongzen5577 2013-04-26 07:42
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function