Can you please tell how to set the UTF-8 encoding in xmlhttprequest to send a request to the Cyrillic? In the server logs such krakozybly: "name": "?????????"? ° ?? "

var xhr = new XMLHttpRequest(); xhr.open("POST", "/registration",false); xhr.send(formData); 

    2 answers 2

    Make sure that :

    1) your files and scripts are created in UTF-8,

    2) your server sends these files to UTF-8

    3) you are viewing the web server logs in a terminal that supports UTF-8

    4) UTF-8 support is installed on your server

    You can download the web server logs, open them in a text editor and see what encoding it recognizes. If everything is readable and the editor shows the UTF-8 encoding, then you have a problem with the terminal.

    Modern browsers by default work in UTF-8, so first check it out, and if you have a specific case when you send requests from a page encoded in cp1251, you probably need to use the answer @Alex Krass

    https://tomcat.apache.org/tomcat-8.0-doc/logging.html , for example, says that tomcat saves logs in the system encoding by default. there is an instruction for switching logging to log4j with utf8

    • Checked in the server debugger (it is in UTF-8) krakozyaby. - Nikolay Egorov
    • What does "checked in server debager" mean? take the log files and see how they open up with a text editor - strangeqargo 5:42 pm
    • I did everything, as you said, I did not find only the server logs (Tomcat) I use .... So far, nothing helped - Nikolay Egorov
    • check on Alex's advice, maybe you really send in 1251 encoding everything. In the browser, you can view the request headers in the developer console. - strangeqargo 5:58 pm
    • And how can you see the headers sent from the client (in the browser console you can)? - Nikolay Egorov

    Through the function setRequestHeader send the desired HTTP header

      var client = new XMLHttpRequest(); client.open("POST", "/registration",false); client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); client.send(formData); 
    • Changed, now the Java controller on the server does not see the requested object. - Nikolay Egorov