How do I post long strings that contain special characters (like '&' specifically) via an AJAX request?
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!
Try calling encodeURIComponent
in your javascript when posting the request.
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.
精彩评论