I'm looking to make a Contact/Query form, wherein the end user can send an email to the webmaster. The form has a 'textarea' field, which captures long strings from the user, if I use AJAX to submit the form using GET method, my params tend to break if their is a special character, specifically '&' in the textarea's string.. I'm stuck please help!
views:
158answers:
3
A:
You can make the string URL safe using JavaScript urlencode...
var textToSend = encodeURIComponent(myform.myfield.value);
This will convert all special characters into URL encoded characters.
Sohnee
2010-03-22 10:40:50
urlencode is supported javascript?
jball
2010-03-22 10:48:42
Are you sure that urlencode exist in javascript? Use encodeURIComponent()!
systempuntoout
2010-03-22 10:52:41
I tried "escape" and it works just fine :)
2010-03-22 10:58:13
Don't use `escape`, it doesn't "work just fine" (unless your data *happens* to fall into the subset of characters which it handles OK). Use encodeURIComponent.
David Dorward
2010-03-22 11:00:58
Yes, I was doing a lot of PHP that day - in JavaScript it is called encodeURIComponent!
Sohnee
2010-03-23 10:31:48
+2
A:
Try calling encodeURIComponent
in your javascript when posting the request.
jball
2010-03-22 10:41:45
Don't use `escape`, it doesn't "work just fine" (unless your data *happens* to fall into the subset of characters which it handles OK). Use encodeURIComponent.
David Dorward
2010-03-22 11:01:26
cool, I'm using the one you suggest..what special characters does 'escape' omit?
2010-03-22 11:08:33
`@`, `+`, `/` ... Check this page out: http://www.the-art-of-web.com/javascript/escape/ especially the table in section 3
jball
2010-03-22 15:39:16
A:
Check this SO question that explain how to encode an url in javascript.
systempuntoout
2010-03-22 10:55:58