2012-10-11 53 views
27

在我的ajax響應中,緩存控制標題顯示在標記中。Symfony Ajax Response顯示緩存標題

HTTP/1.0 200 OK緩存控制:無緩存日期:星期四,2012年10月11日 九時00分59秒GMT

我期望的報頭是在報頭,而不是在標記。

這裏是我的控制器操作摘錄:

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

這是爲什麼,我怎麼能做出這樣消失了?

+0

請添加更多代碼示例 - 您如何處理客戶端中的數據等。 –

+0

通過jquery獲取視圖:result_div.load(route); – ivoba

回答

76

方法render()顯示標題。可以使用方法renderView()。此方法不顯示標題,只是生成html。

希望它有幫助。 :)

+1

是的,這是它! thx – ivoba

+2

謝謝! KnpSnappyBundle和wkhtmltopdf的最佳解決方案 –

+0

這讓我瘋狂,並且這固定了它 - 謝謝! –

11

您可以做

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

或者做

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

二是比較合適的。

+0

不適用於我的情況。 – SunUser