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
<strong>some html</strong> <br /> more text.
which when included in html display:
<strong>some html</strong> <br /> more text.
Comments
Post a Comment