After receiving an AJAX response, the class "navtex-message" doesn't work properly when I create HTML with JavaScript.
function formatNtxMessage( m ) {
return '<div class="row">' +
'<div class="col-lg-9">' +
'<div class="navtex-message">' +
JSON.stringify(m.content).replace(/\"/g, "") +
'</div>' +
'</div>' +
'</div>';
}
function format ( d ) {
var div = $('<div/>')
.addClass( 'loading' )
.text( 'Loading...' );
$.ajax( {
type: "GET",
url: '/api/ntxMessage/' + d.id,
success: function ( json ) {
div
.html(formatNtxMessage(json.data))
.removeClass( 'loading' );
}
} );
return div;
}
The ".navtex-message" class is causing text to break into new lines instead of displaying \r\n:
.navtex-message {
white-space: pre-line;
}
Here is the string that I receive:
ZCZC QE02\r\n050640 UTC MAR\r\n\r\nSPLIT RADIO\r\n\r\nWEATHER BULLETIN FOR ADRIATIC\r\n\r\nISSUED BY THE MARINE METEOROLOGICAL CENTER SPLIT ON 05/03/2018 AT 0400 UTC\r\n\r\n1. WARNING:\r\n\r\nISOLATED GUST OF SE / NE WIND, IN THE EVENING NW 35-45 KTS, IN VELEBIT STRATE NW TO 55 KTS. POSSIBLE SUDDEN STORMS. \r\n\r\n2. SYNOPSIS:\r\n\r\nTROUGH WITH FRONTAL DISTURBANCE APPROACHED TOWARD ADRIATIC FM THE WEST.\r\n\r\n3. FORECAST FOR THE NEXT 24 HOURS VALID UNTIL 06/03/2018. AT 0400 UTC\r\n\r\nN-ERN ADRIATIC:\r\n\r\nNE, OFFSHORE AT FIRST SE, IN THE EVENING AND OVERNIGHT NW...
Why am I getting line breaks instead of \r\n?