Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json returned my HTML <br /> in unicode form \u003cbr /\u003e . Causing the <br /> printed as a text rather than making a new line

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>
like image 204
Bing Zhao Phua Avatar asked Nov 15 '22 03:11

Bing Zhao Phua


1 Answers

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.

like image 173
Jake H. Avatar answered Nov 16 '22 17:11

Jake H.