Need to display the stored email body content in a html page.
$.ajax({
type: "POST",
url: "./mailBody.php",
dataType: 'json',
success: function (data) {
$.each(data, function(index, element) {
$('.mailBody').html(element.msgbody);
});
From mailBody.php Im getting following kind of a email body String from back end. But when inserted into the html page it does not render as html.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000099"><br></div><div class="gmail_quote"><br><div dir="ltr"><div><font color="#000099" face="tahoma, sans-serif">test for message idtest for <strong>message id<strong/>test for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message idtest for message id</font><br></div></div>
</div><br></div>
you need to trim the newline and return
characters to make it HTML. try using the
String.trim()
function to remove them.
Try using jQuery.parseHTML
$('.mailBody').html($.parseHTML(element.msgbody));