$data = json_encode( array('type'=>$type,'params'=>$params) );<br>
$headers = array( 'Content-type' => 'application-json; charset=utf8' );<br>
$responce = new \Symfony\Component\HttpFoundation\Response( $data, 200, $headers );<br>
return $responce;<br>
use Symfony\Component\HttpFoundation\Response;
...
$response = new Response(json_encode(array('name' => $name)));
$response->headers->set('Content-Type', 'application/json');
ExampleBundle_loadData:
pattern: /data.{_format}/{type}/{params}
defaults: { _controller: ExampleBundle:Default:loadData, _format:json }
requirements: { _format: json|xml }
public function loadDataAction($type, $params)
{
$return = array('type'=>$type,'params'=>$params);
return $this->render('ExampleBundle:Default:ajax.json.twig', array('data'=>$return));
}
{{data|json_encode|raw}}
use Symfony\Component\HttpFoundation\Response;
$response = new Response();
$response->setContent(json_encode(array(
'data' => 123,
)));
$response->headers->set('Content-Type', 'application/json');