通常在 xhr 操作中我使用这段代码
$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));
我想知道是否需要这样的utf-8编码
$response->setHeader('Content-type', 'application/json;charset=UTF-8', true);
最佳答案
这样做是个好习惯。如果不这样做,您可能看不到任何问题。这取决于您发送的数据类型。
有一种更短的方法可以完成您正在做的事情(禁用布局并设置正确的标题):
$this->_helper->json->sendJson($data);
关于php - Zend 响应应用程序/json utf-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6445843/