ApoY2k
2011-07-31 12:59:26 UTC
I want to create an XHR-Controller that responds with JSON-Objects.
So I create an array in that controller an pass it to the twig-template.
$response = array('message' => 'hello');
return $this->render('MyBundle:Xhr:message.json.twig');
In the template, I encode the array using json_encode
{{ message|json_encode }}
But the returned template isn't recognized as a JSON-Object, but as a
string. It seems that the string is escaped and jQuery therefore doesn't
recognize it as an object, but as a normal string.
How can I get the JSON-Object in JavaScript to be parsed correctly?
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
So I create an array in that controller an pass it to the twig-template.
$response = array('message' => 'hello');
return $this->render('MyBundle:Xhr:message.json.twig');
In the template, I encode the array using json_encode
{{ message|json_encode }}
But the returned template isn't recognized as a JSON-Object, but as a
string. It seems that the string is escaped and jQuery therefore doesn't
recognize it as an object, but as a normal string.
How can I get the JSON-Object in JavaScript to be parsed correctly?
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en