jquery - Output HTML in JSON string generated by PHP -


i have php outputs json.

<?php $html = utf8_encode($gegevens['tekst']); $html = htmlentities($html); //$html = htmlspecialchars($gegevens['tekst'], ent_quotes, 'utf-8'); echo json_encode(array( 'titel' => $gegevens['titel'], 'html' => $html )); ?> 

the output like:

{"titel":"here comes title","html":"<strong>here html<\/strong>\n<br \/>\n<br \/>\n     , more."} 

and jquery/ajax be:

$.ajax({                             type: "get",                             url: "content/popup.php?id=" + id2,                             datatype: 'json',                             crossdomain: true,                             success: function(json) {                             var titel = json['titel'];                             var html = json['html'];   function contenttonen() {                                 // div's legen van content $('.popup_home_head_inside').empty(); $('.popup_home_content_inside').empty();  $('.popup_home_head_inside').html(titel); var html2 = html.replace(/\"/g, ""); //$('.popup_home_content_inside').html(html2); $('.popup_home_content_inside').html(html2); 

and html output is:

<strong>some html</strong> <br /> more text. 

so not process html.

can me out?

you need not escape html htmlentities on server side.

remove $html = htmlentities($html); php file.

reason: htmlentities convert

<strong>some html</strong> <br /> more text. 

to

&lt;strong&gt;some html&lt;/strong&gt; &lt;br /&gt; more text. 

which when included in html display:

<strong>some html</strong> <br /> more text. 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -