usually in a xhr action I use this code
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$response = $this->getResponse();
$response->setHeader('Content-type', 'application/json', true);
return $response->setBody(Zend_Json::encode($data));
I'm wondering if it need utf-8 encoding like this
$response->setHeader('Content-type', 'application/json;charset=UTF-8', true);
It would be good practice to do so. You may not see any problems if you don't. It depends what kind of data you are sending.
there is a much shorter way to do what you are doing (Disables layouts and sets the right headers):
$this->_helper->json->sendJson($data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With