Unterminated string literal for db data in javascript -


here code output passing data console:

 console.log(' fun, friendly,  * new private party room stage, 70" satellite tv, comfortable lounge seating exciting bachelor parties, unique surprise birthday parties, divorce, retirement....you own it! party includes: 90 minutes open bar, dedicated waitress, complimentary dance of choice guest of honor, '.trim()); 

my result is: syntaxerror: unterminated string literal.

i understand issue breaking new lines in javascript , need use \ dynamic data follows:

var b = '<xsl:value-of select="./description"/>'; <--- output above gets assigned here 

so, how resolve issue? the application not outputting text on log. showing blank should replace \n \ ?

not quite sure of solution.

the easy solution escape newlines. want keep \n, in string literal form.

let me give example...

you have "\n", literal newline. want "\n", first slash escapes second.

you can't replace "\" "\" (or "\" "\\", follow correct escaping), because "\n" 1 character.

what want simply

yourstring.replace(/\n/g, "\\n"); 

this performs regexp substitution on string (the first argument pattern for. use "g" flag - global - every newline replaced, not first one). second argument replacement - in our case, it's string literal, if needed generated value based on matched pattern, use function.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -