PDA

View Full Version : how to load multiline data in textarea with JSON



gkassyou
5 Jun 2007, 11:54 AM
I have a form and a textarea within it. My form loads using JSON. my textarea is a notes field which should have multiple lines. When I read the data, JSON complains because of the multiline.

How to load my textarea using JSON with multiline data from my DB.

Thx

ex of JSON returned from DB:
{'notes':'this is a
test field info
.asdasdasd'}

tryanDLS
5 Jun 2007, 11:58 AM
How are the linebreaks being passed back from the server? You may have to change the encoding?

midoalone
13 Apr 2011, 3:22 AM
Hello ,
I know that the thread is very old ,
but i searched a lot to find the answer .

to load multiline data in textarea you simply need to escape the \ that will generated when you insert a new line in the form of \n .

so you need to replace \n with \\n ( server side replace )
in php you can do it as follow :

str_replace("\n","\\n",$data); where $data is the json encoded data .

Hope it be useful for you , thank you all .:)