in the form unicode \ u003cbr / \ u003e. Causing
printed as text, not creating a new line I am using ASP.n...">

Json returned my HTML <br/ "> in the form unicode \ u003cbr / \ u003e. Causing <br/"> printed as text, not creating a new line

I am using ASP.net MVC3 and I have returned the model which is in Json format using Jquery.AJAX and then pass it to the jQuery template for printing. A.

For example, Json, which returned the server, {"Key":2,"Content":"I'm Jason\u003cbr /\u003ehow are you"} instead {"Key":2,"Content":"I'm Jason <br /> how are you"}

when I add it to the Div using the jQuery template, it prints something like this:

I'm Jason <br /> how are you

while the intended result should be

I'm Jason 
how are you

I suppose the server does not encode the string on the server side? But I think this may cause a security problem. So I think I need to decode the Json string on the client side, but so far no luck. Can someone show me a suitable way to deal with this problem?
thank

* Updated
I tested using jQuery('#someDiv').append(data.Content);and printed it out as I see fit.
So the problem is probably related to the jQuery template

I use this code to transfer data to a jQuery jQuery('#someTemplate').tmpl(data).appendTo('#someDiv');

template. My jQuery template

<script id="someTemplate" type="text/x-jquery-tmpl">
 <div>${Content}</div>
</script>
+3
source share
3 answers

I ran into this problem. No need for encoding / decoding or escape / unescape.

Instead of this:

${Content}

:

{{html Content}}

HTML.

+1

, :

alert(unescape('\u003cbr /\u003e'));
0

I have the same problem with ajax templates. the line has \ n which is ignored in the template, and if I convert \ n to <br/>, then instead of the line it will be displayed <br />.

if I use {{ unscape(myString) }}, then the result is still "some text on the <br />next line"

0
source

Source: https://habr.com/ru/post/1787699/


All Articles