You say: "XMLHttpRequest always changes data to UTF-8 before sending."
WHAT IS WRONG!!! XMLHttpRequest must be encoded before sending, the encoding is determined by the document itself.
for html5, you can use <meta charset="YOUR-ENCODING-HERE">
. for html or xhtml, you should use <meta http-equiv="Content-Type" content="text/html; charset=YOUR-ENCODING-HERE-WITHOUT-QUOTES">
. for xml you can use <?xml version="1.0" encoding="YOUR-ENCODING-HERE"?>
.
then before XMLHttpRequest.send () you need XMLHttpRequest.setRequestHeader("Content-type","SOME-OTHER-DECLARATION; charset=YOUR-ENCODING-HERE-WITHOUT-QUOTES");
.
Given all of the above, no matter what encoding your server uses by default, it will use the encoding offered by the offer (if it supports) to decode the URI.
There is another way to do this.
I do not know which programming language is used on your server side. For java, you can use, for example, str
is the string received by the server, newStr = new String(str.getBytes("SERVER-ASSUMED-CHAR-ENCODING"), "YOUR-HTML-ENCODING");
In your case, it will be newStr = new String(str.getBytes("windows-1251"), "UTF-8");
. And newStr should be readable data.
source share