[英]How to post a HTML form using Javascript that has both “application/x-www-form-urlencoded” and “charset=UTF-8” in the Content-Type header
I need to be able to specify using Javascript how to post a form that contains both the enctype as "application/x-www-form-urlencoded" and charset as "charset=UTF-8" in the Content-Type header. 我需要能够使用Javascript指定如何在Content-Type标头中发布同时包含enctype作为“ application / x-www-form-urlencoded”和charset作为“ charset = UTF-8”的表单。 Any ideas? 有任何想法吗?
I have a aForm object of type Form. 我有一个Form类型的aForm对象。
Thanks! 谢谢!
Last I checked, you simply can't rely on being told the charset of a form submit. 最后我检查了一下,您根本不能依靠告诉表单提交的字符集。 Most sites either assume the charset (hopefully UTF-8 on modern sites) or they pass it in a separate query parameter. 大多数站点都采用字符集(希望在现代站点中为UTF-8),或者在单独的查询参数中传递字符集。
Assuming that the charset will be something in particular isn't as crazy as it sounds. 假设字符集将是特别的东西,听起来并不疯狂。 Every browser in common use will use the same encoding for submitting a form as the page that contained the form. 每个常用的浏览器都会使用与包含表单的页面相同的编码来提交表单。 So if you send the HTML page containing the form in UTF-8, you can pretty safely assume the submission will also be in UTF-8. 因此,如果您以UTF-8格式发送包含表单的HTML页面,则可以很安全地假定提交内容也将以UTF-8格式提交。
尝试.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded;charset=UTF-8' );
"application/x-www-form-urlencoded" and utf-8 cannot be used together.I too had "application/x-www-form-urlencoded", While accepting request in doPost method of servlet try request.setCharacterEncoding("UTF-8"); “ application / x-www-form-urlencoded”和utf-8不能同时使用。我也有“ application / x-www-form-urlencoded”,但是在servlet的doPost方法中接受请求时请尝试request.setCharacterEncoding(“ UTF -8“); worked for me for multilingual characters after much searching 经过大量搜索后为我工作的多语言字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.