Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Ajax Response displays cache header

Tags:

symfony

In my ajax response the Cache-Control Header is displayed in the markup.

HTTP/1.0 200 OK Cache-Control: no-cache Date: Thu, 11 Oct 2012 09:00:59 GMT

I expected the header to be in the headers and not in the markup.

Here is my controller action excerpt:

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

Why is this and how can i make this disappear?

like image 214
ivoba Avatar asked Oct 11 '12 09:10

ivoba


2 Answers

The method render() display headers.

You can use method renderView(). This method don't display headers, just the generate html.

Hope it's helpful. :)

like image 139
Benjamin Lazarecki Avatar answered Sep 29 '22 12:09

Benjamin Lazarecki


You can either do

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

Or do this

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

Second is more appropriate.

like image 25
Venkat Kotra Avatar answered Sep 29 '22 12:09

Venkat Kotra