开发者

How do I post long strings that contain special characters (like '&' specifically) via an AJAX request?

开发者 https://www.devze.com 2022-12-24 18:12 出处:网络
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开发者_如何学编程 u

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消