escape exactly what in javascript
Posted
by Emin
on Stack Overflow
See other posts from Stack Overflow
or by Emin
Published on 2010-05-21T07:49:57Z
Indexed on
2010/05/21
7:50 UTC
Read the original article
Hit count: 196
Hi all,
Being a newbie in javascript I came to a situation where I need more information on escaping characters in a string.
Basically I know that in order to escape "
I need to replace it with \"
but what I don't know is for which characters I need to escape a particular string for. Is there a list of these "characters to escape"? or is it any character that is not a-zA-Z0-9
?
In my situation, I don't have control over the content that is being displayed on my page. Users enter some text and save it. I then use a webservice to extract them from the database, build a json array of objects, then iterate the array when I need to display them. In this case, I have - naturally - no idea of what the text the user has entered and therefore for what characters I need to escape. I also use jQuery for this specific project (just in case it has a function I am not aware of, to do what I need)
Providing examples would be appreciated but I also want to learn the theory and logic behind it.
Hope someone can be of any help.
© Stack Overflow or respective owner