【问题标题】:Symfony Ajax Response displays cache headerSymfony Ajax 响应显示缓存头
【发布时间】:2012-10-11 09:06:37
【问题描述】:

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

HTTP/1.0 200 OK 缓存控制:无缓存 日期:2012 年 10 月 11 日,星期四 格林威治标准时间 09:00:59

我希望标题在标题中而不是在标记中。

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

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

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

【问题讨论】:

  • 请添加更多代码示例 - 您如何处理客户端中的数据等
  • 视图通过 jquery 获取:result_div.load(route);

标签: symfony


【解决方案1】:

方法render()显示标题。

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

希望对您有所帮助。 :)

【讨论】:

  • 谢谢! KnpSnappyBundle 和 wkhtmltopdf 的最佳解决方案
  • 这把我逼疯了,这解决了它 - 谢谢!
【解决方案2】:

你可以这样做

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

或者这样做

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

第二个更合适。

【讨论】:

  • 在我的情况下不起作用。
猜你喜欢
  • 2013-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-08
  • 2014-01-07
  • 2020-07-06
  • 1970-01-01
  • 2013-06-24
相关资源
最近更新 更多