Symfony Ajax Response显示缓存标头

ivo*_*oba 30 symfony

在我的ajax响应中,Cache-Control Header显示在标记中.

HTTP/1.0 200 OK缓存控制:无缓存日期:2012年10月11日星期四09:00:59 GMT

我希望标题位于标题中而不是标记中.

这是我的控制器动作摘录:

...
$template = $this->render('list.html.twig', array(
                'data' => $data
                    ));
return new Response($template);
...
Run Code Online (Sandbox Code Playgroud)

为什么这样,我怎么能让它消失?

Ben*_*cki 87

该方法render()显示标题.

你可以使用方法renderView().此方法不显示标题,只显示生成html.

希望它有用.:)

  • 谢谢!KnpSnappyBundle和wkhtmltopdf的最佳解决方案 (2认同)

Ven*_*tra 12

你可以这样做

$template = $this->render('list.html.twig', array());
return new Response($template->getContent());
Run Code Online (Sandbox Code Playgroud)

或者这样做

$template = $this->renderView('list.html.twig', array());
return new Response($template);
Run Code Online (Sandbox Code Playgroud)

第二种更合适.