I am trying to load multi-line text from a MySQL database in开发者_C百科to a JavaScript variable, but it doesn't work.
I get the text from the database, then add the text to a spring model as its attribute "mytext
".
In a jsp file, I want to retrieve the text, so I have code like this:
var text = '<c:out value="${mytext}"/>'; //multy-line text
alert(text);
The above code fails, and the function alert()
would not be called.
If the text from the database is single-line, it goes well.
How can this be fixed in script code?
You can use a character sequence to join the multiline text into one line (server side) and then split the text using javascript using the same character sequence.
精彩评论