I’ve seen some question here about almost the same thing, but, after following their suggestions I keep getting the same behavior.
I’m constructing the json object in my action as follows:
return $this->renderText(json_encode(array(
'html' => addslashes($this->renderPartial('global/formWrapper',
array(
'form' => $nareas,
'url' => $this->generateUrl('new_promo_step2'),
'cancelUrl' => 'new_promo',
))),
'error' => true)));
and Im getting the following response:
<html>
The html content which is supposed to be in the "html" property of my json
object...
</html>{"html":"None","error":true}
along with a header with a Content-Type:text/html; charset=utf-8.
In my jQuery ajax request, I’ve set the dataType as ‘json’ (and of course I get an unexpected character error), and as ‘text’ (and I get no error, but keep getting the malformed json)
I’ve tried using addslashes() (as in the example), and without this function; tried using the ESC_RAW symfony option, and got the same.
I’m expecting to get something like this:
{"html":"<html>Html content</html>","error":true}
Please! any help would be strongly appreciated!
Thanks!
To render a partial from the action you will need to load your partials as an include and use getPartial to retrieve it into your renderText call.