I'm using Jquery to submit the value of a <textarea>
through AJAX to a PHP script. This value may contain punctuation characters (!,?,#,@)
as well as single and double quotes, and other non-alphanumeric characters. Does Jquery take care of encoding all this stuff or do I need to do it myself? How can I be certain that whatever the user typed in the <textarea>
would be submitted?
views:
198answers:
2
+1
A:
Yes, jquery will care about that. but always add the correct encoding to the page you are browsing at. in my case I try to use always utf-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Gabriel Sosa
2009-04-25 15:36:03
+2
A:
I use encodeURIComponent for that. If there's a risk the text contains a '%'-sign, i replace that with it's htmlcode (&#something) before encoding.
KooiInc
2009-04-25 15:36:53
encodeURIComponent will correctly encode % to %25
Greg
2009-04-25 15:40:26
Doesn't jquery automatically do that?
Click Upvote
2009-04-25 16:38:07
@Greg, you're right. I remember having had problems with %, but could be long time ago.@Click Upvote, Sorry, I don't use jquery.
KooiInc
2009-04-25 19:35:10
@Click Upvote again: check http://malsup.com/jquery/form/comp/. At the bottom it says: "Each of the libraries tested use JavaScript's encodeURIComponent function to encode form data." So theoretically using jQuery, you wouldn't need encodeURIComponent?
KooiInc
2009-04-25 21:37:39