简体   繁体   中英

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é'

obs: I can't change anything in server side.

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).

Any help is welcome !

Try this :

myForm.acceptCharset = "UTF-8";

Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM