I have this problem:
I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line).
Then I take The value of The textarea using the command:
document.getElementById("textareaCommento")
And I pass The value to the servlet using an XmlHttpRequest.
In The servlet I save this value in a database.
Since this point I have no problems...
Then, in another part I want to get The values from The database. Using a servlet I make this query
Select * from comments
And I transform the results in json. Here I have The problem... The newline character makes my JSON string invalid. For example:
"Comment":"hello
Word"
How can I do?
Thanks in advance!
You have to replace the \n character from database to something like <br/>
For the replace see replace \n and \r\n with <br /> in java
this CSS worked for me,
white-space: pre-line;
You should be able to url encode your values so hello world would actually become "hello%20world", to do it in java see here:
Encoding URL query parameters in Java
To do it in javascript see here:
Encode URL in JavaScript?
Related
I have a doubt in creating a blog. Take stackoverflow.com as example, In this, ask question or answer segment have a WYSIWYG like editor. If i use some href link or other html tags within my answer how the data format stored in database(In HTML or plain text or any other).
In case data is stored in HTML format, then how it is converted simple json for connecting with mobile app webservice's.
In simple question, In which format user data is stored in database and how it is used for further processing.
I'm not sure how it works on Stack Overflow, but I think the text is stored in database in plain text format but with special characters like:
[link](http://example.com); _italic_; **bold**
And then these symbols are replaced with actual markup
The value "\1014" is coming from my database and I want to display it in an ExtJS Panel.
The problem is, it gets processed as an entity value, and "A4" is displayed instead
I don't want to have to do entity encoding on the back end.
I tried
Ext.util.Format.htmlEncode('\1014')
But this also returns "A4"
What is the correct way to encode such values on the front-end for display?
This has nothing to do with ExtJS. This is a builtin feature of JavaScript and JSON. If you want to send the non-literal \101 as JSON to the frontend, you have to escape the backslash correctly to the specs in the backend:
{"success":true,"data":{"test":"\\101","id":"extModel2-1"}}
If you don't escape the backslash, it will be converted to the appropriate literal immediately when it hits the frontend and is then indistinguishable from the letter A, so this is not revertible on the frontend.
Relevant fiddle
Relevant older answer
You can parse data using JSON.parse(response.reponseText) instead of Ext.decode
I am using a text area field in Salesforce as a RecipientNote for a Docusign envelope created using a custom button in Salesforce.
The syntax below handles any commas or special characters, but I'm unable to find the correct syntax to preserve any linebreaks in the Program_Exception_Notes__c field.
;RecipientNote~{!JSENCODE(URLENCODE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,",","_COMMA_")))}
I have tried the following but none worked. Any ideas?
'{!SUBSTITUTE(JSENCODE(URLENCODE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,",","_COMMA_"))),"%0D%0A","\\n")}'
'{!JSENCODE(URLENCODE(SUBSTITUTE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,"\r\n","\\n"),",","_COMMA_")))}'
I would process your text in a couple of steps in jscript.
first break the text into an array of string lines
escape characters you are looking to correct
then reassemble using the "\n" when you put it back together into a var
Then after all that, URL and JS encode that string variable.
I don't know if this question is so stupid but...
How can i add a newline character to a database registry?
I just want to add a new line character after the input that is shown to the user in the edit or add form.
For example:
//edit view
echo $this->Form->input('reply_above');
I want to send a mail with some information and this string should be at the top separate from the rest of the mail message by a newline.
I have tried this at the edit action in the controller:
$this->request->data['Setting']['reply_separator'].= '<br />';
But then, when i use the mail function it shows the <br /> instead of printing it. (and i really don't want to send the mail in HTML format)
The texts stored on the database don't use a <br /> for new lines. What do they use instead? I have also tried \n but it doesn't work either.
Thanks.
UPDATE
I could be able to add a new line doing this in the edit controller before saving the data:
$this->request->data['Setting']['reply_separator'].="
";
But it really doesn't look like a good solution plus i can not add more than one newline with this method.
Any solutions?
This is your new line character: "\n".
Edit: Be sure to use double quotes not single quote.
I'm trying to have a mailto: body with multiple paragraphs and a URL. I should probably note this is for a mobile web application.
Is there a reason why I can't use \n (even inside JavaScript strings) for new lines? Instead, I'm using %0D%0A.
I'd like to enclose my URL in <>'s so email clients can properly identify it as a URL, but when I try to do that the entire URL doesn't show up at all in the body. Is it being escaped, or something? How do I fix this/use <>'s to wrap it?
Thanks!
have you tryed encoding the values with javascript?
eg
<a href="demo#email.com?subject='+encodeURI('emailSubject')+'&body='+encodeURI('emailBody')+'">