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.

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.