Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 496
Whisher Avatar asked Jun 22 '11 20:06

Whisher


1 Answers

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);
like image 127
datasage Avatar answered Oct 07 '22 04:10

datasage