Zend response application/json utf-8
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);
You should better use contextswitch/ajaxcontext helper. See example in first answer there.
精彩评论