"-Lost" <ma****************@techie.comwrote in message
news:JP******************************@comcast.com. ..
For example:
var newlines = 'a\n\nb\n\nc';
'a\n\n\b\n\n\c' above contains the letter 'a' then the character '\' then
the letter 'n' then '\' then 'n' then 'b'
The value of the variable newlines above is, after parsing of 'a\n\nb\n\nc'
by the interpreter and assigning the result to the variable, the letter 'a'
then a newline then newline then the letter 'b' then...
alert(newlines);
Yet, if I get that *exact* same line from an XMLHttpRequest's
responseText, it is always alerted as:
a\n\nb\n\nc
It's not the "exact same line".
What you get in the response text is the string 'a\n\n\b\n\nc'.
What you get up the top there is this string parsed by the javascript
interpreter who carefully translates the character sequence \n to a newline
character.
BTW xhrObj.responseText.replace(/\\n/mg,"\n"); is not translating \n into
\n, or even a newline into a newline. It is searching for the two character
string, \n, with the \ escaped of course, so we write it /\\n/. It is
replacing occurrences of this string with something, the something being the
string "\n" which has of course been parsed by the interpreter into a string
containing the single character 'newline'.
--
Richard.