开发者

loading multy-line text from database into javascript variable error

开发者 https://www.devze.com 2023-03-11 00:38 出处:网络
I am trying to load multi-line text from a MySQL database in开发者_C百科to a JavaScript variable, but it doesn\'t work.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消