How to use carriage return or line feed in the query string?
the customers can enter lines in a text area and this is saved in the database.
If the customer comes back to the site he can load the previously entered data.
However, the line feeds and carriage returns aren't displayed in the text area.
I can place them in the query string for example by ASCII coding them: %A or %D but java doesn't like that and throws an IllegalArgumentException.
So I do now: %5Cn and %5Cr which gives: \n and \r
How can I make javascript to display the escaped new lines as actual new lines in the text area?
The URL开发者_开发百科 is something like:
http://www.abc.com?textarea=line1%5Cn%5Crline2
and I want the line1 and line2 to be on two different lines in the textarea.
%5C
is a literal backslash - so %5Cn
means just "backslash and then the letter n". What you probably want is %0A
and %0D
instead of %A
and %D
. But you should URL-encode the entire string properly and not just encode two characters by hand. Use encodeURIComponent()
. Also, use POST
instead of GET
, but not because the string is multiline but because you are storing it in the database. You shouldn't use the GET
method for operations that are not idempotent.
Using GET (query string) to enter multi-line data is wrong. You should be considering POST instead.
精彩评论