Ajax 将细枝渲染为JSON对象

Ajax 将细枝渲染为JSON对象,ajax,json,symfony,twig,Ajax,Json,Symfony,Twig,我有一个细枝模板,我想呈现,存储在JSON对象中,并作为对post请求的响应返回 $response = json_decode('{"version":1,"status":"success"}', true); $html = $this->render('DumoBundle:Test:Overlay.html.twig', array('left'=>3,'right'=>4)); $response['html'] = $html; $response=

我有一个细枝模板,我想呈现,存储在JSON对象中,并作为对post请求的响应返回

$response = json_decode('{"version":1,"status":"success"}', true);
$html = $this->render('DumoBundle:Test:Overlay.html.twig', 
     array('left'=>3,'right'=>4));
$response['html'] = $html;
$response= new Response(json_encode($response));
return $response
但是,当我将JSON对象打印到浏览器端的控制台时,我看到如下所示:

{"version":1,"status":"success","html":{"headers":{}}}

如何将所有HTML存储在JSON obejct的
HTML
属性中

我发现了一个错误:。但我不想删除,因为这将使其他寻找此解决方案的人有两倍的机会找到它。仅供参考,您也不需要使用
json\u encode
作为响应。Symfony有一个特定的
JSONResponse
类(Symfony\Component\HttpFoundation\JSONResponse),它将为您处理这些内容(头、json_编码等)。