In a reply from my latest post after following the comments, there is a much elegant solution to this use case. Simply by changing the output with a JSON helper. This also changes the content-type of the returned response.
$data = array(...); $this->_helper->json($data);
Related posts:
- Returning JSON in a Zend Controller’s Action
- JSON and Zend Framework? – Zend_Json
- Bind Zend Action with Non-Default View – Part 2




Nice! Now that makes things interesting, thank you for sharing.
Thanks for the correction. If your action is going to return just JSON and always JSON, the Json Helper is the best option, in case your action can return different formats (Xml, Json, Yaml, etc.), ContextSwitch or AjaxContext are better.
Best!
My bad, i forgot to translate this.
I’m looking for a long time, for a way to return the ID of an element selected from the autocomplete.
If you have any feedback, please send me an email.
Sorry i don’t really get how u to it. Do u still need a view script for this second method u psoted?
for example i have an action named
public function getAllJsonAction()
{
$data = array();
$this->_helper->json($data);
}
Do i still need a getAllJson.phtml???
Cheers! Many thanks!
@j3r – No, you don’t need a view script!