Skip to content
Advertisement

Joomla – Controller task that returns JSON data

I have the task run in my controller. I want it to return JSON data. As it stands, I am getting my JSON data wrapped inside the template HTML. How do I tell Joomla to just return JSON data from the controller? This is the function I have:

JavaScript

And this returns:

JavaScript

I would like to get:

JavaScript

Advertisement

Answer

You don’t need to build a special JSON view (view.json.php; or controller progressreports.json.php) to achieve that. The only thing you have to do is to echo the JSON string and close the application.

JavaScript

You only need a separate view (or controller), if you want to provide the same function with both HTML and JSON output (chosen by the caller).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement