I normally append an encoded json object to the response body, however I now have a situation that warrants using the ContextSwitch action helper.
I have a Zend_Form
Personally, I don't use "View" to generate JSON content.
In my init()
, I have something like this:
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->setAutoJsonSerialization(false)
->addActionContext('index', array('html', 'json'))
->initContext();
And In my indexAction()
:
if ( true === $this->isAjaxJson() ) {
$this->_helper->json(
array(
'response' => $myResponse,
'message' => $myMesage
)
);
return;
}
Hope this help.
this may help :
$this->_helper->json->sendJson($data);
while,
$data=array('data1'=>'val1','data2'=>'val2');