简体   繁体   中英

display the stored email body content in a html page

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"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<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>\r\n</div><br></div>\r\n

you need to trim the newline \\n and return \\r characters to make it HTML. try using the String.trim() function to remove them.

尝试使用jQuery.parseHTML

$('.mailBody').html($.parseHTML(element.msgbody));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM