In HTML, linebreaks are represented by <br> tags, not CRLF characters.
You need to either replace the CRLF characters with <br> tags, or to apply CSS white-space:pre to the containing HTML element, and use text() instead of html() .
Replacing CRLF with <br> can be done in various ways. On the server side, before returning strData to JavaScript. For example, when you use Java:
strData = strData.replace("\\n", "<br />");
Or on the client side using JavaScript itself:
strData = strData.replace(/\n/g, "<br />");
source share