I'm using ASP.net MVC3 and i returned a model which is in Json format using Jquery.AJAX and then I pass it into a Jquery template to be printed out.
For example the Json that server returned is
{"Key":2,"Content":"I'm Jason\u003cbr /\u003ehow are you"}
instead of
{"Key":2,"Content":"I'm Jason <br /> how are you"}
when I append it into an Div using Jquery template it printed out something like this:
I'm Jason <br /> how are you
while the intended result should be
I'm Jason
how are you
Am I suppose to prevent the server from encoding the string in server side? But I think this may cause security issue.
Therefore I think I have to decode the Json string in client side but no luck so far. Can anyone show me an appropriate way to deal with this kind of problem?
Thanks
*Updated
I tested with jQuery('#someDiv').append(data.Content);
and it print out as intended.
So the problem is probably related to Jquery template
I'm using this code to pass data into Jquery template jQuery('#someTemplate').tmpl(data).appendTo('#someDiv');
My Jquery template
<script id="someTemplate" type="text/x-jquery-tmpl">
<div>${Content}</div>
</script>
I ran into this same issue. No need encode/decode or escape/unescape.
Instead of this:
${Content}
Use this:
{{html Content}}
The unicode with be displayed as HTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With