简体   繁体   English

如何将动态形式的字符集设置为UTF-8?

[英]How set the charset of dynamic form to UTF-8?

I have a form created dynamically with one input: 我有一个输入动态创建的表单:

var myForm = document.createElement('form');
myForm.setAttribute('id', 'formDynamically');   
myForm.method = 'POST';
myForm.action = 'myAction';

var myInput = document.createElement('input');
myInput.type = 'text';
myInput.name = 'textDescription';
myInput.value = $('#myTextField').text();
myForm.appendChild(myInput);    

document.body.appendChild(myForm);
myForm.submit();

My problem is: 我的问题是:

If the user types a text with accentuation, in the server the letters arrive strange 如果用户输入带有重音符号的文本,则服务器中的字母会变得奇怪

Exemple: 'fiancé'. 例如:“未婚夫”。 in the server side i recived ---> 'fiancé' 在服务器端,我收到--->'fiancé'

obs: I can't change anything in server side. obs:我无法在服务器端进行任何更改。

obs²: I tried it with Jquery Ajax and works fine, the problem really is with my form (i can't use ajax, i must do it with form submit). obs²:我使用Jquery Ajax尝试了一下,并且工作正常,问题确实出在我的表单上(我不能使用ajax,我必须使用表单提交来完成)。

Any help is welcome ! 欢迎任何帮助!

Try this : 尝试这个 :

myForm.acceptCharset = "UTF-8";

Documentation 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在javascript文件中设置charset =“utf-8” - How to set charset=“utf-8” in the javascript file itself 在jQuery.getScript()中,我们如何将字符集类型设置为utf-8? - In jQuery.getScript(), how do we set the charset type to utf-8? 如何在角度js中将charset utf-8设置为$ http GET和POST的标头 - how set charset utf-8 to header to $http GET and POST in angular js 如何将上传的文件从 charset=iso-8859-1 转换为 charset=utf-8? - How to convert uploaded file from charset=iso-8859-1 to charset=utf-8? 如何使用在Content-Type标头中同时具有“ application / x-www-form-urlencoded”和“ charset = UTF-8”的Javascript发布HTML表单 - 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 外部JavaScript文件的Charset UTF-8 - Charset UTF-8 for external JavaScript file HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported encodeURIComponent 和 content-type: 'charset: utf-8' - encodeURIComponent and content-type: 'charset: utf-8' URL.createObjectURL和字符集UTF-8 - URL.createObjectURL and charset UTF-8 javascript 在 ES 模块中使用字符集 utf-8 导入 - javascript import with charset utf-8 in ES module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM