Good afternoon!

The situation is this: there is an ajax request from jquery, which takes something and inserts it into the page. There is this same page with some kind of encoding.

Question: Is it possible to make sure that the answer returned by the Ajax always corresponds to the page encoding? (to avoid problems with the display of Russian characters)

That is, do so:

  1. take the charset value from the meta tag
  2. send it in ajax request to the server
  3. on the server put the desired encoding in the response header

Question: Is this a normal way? What is the best way to determine the encoding of the page requesting the server: to transfer manually what you have learned through js or to watch the request headers or something?

  • If you have java, it was necessary to specify in the tags;) corrected. - Ozim

2 answers 2

Ajax works with utf8, iconv when answering and sending, and everything will be sweet, and even better to switch completely to utf8, and there won't be such a headache ... there really will be another smut.

  • It is interesting to know what kind of headache will appear with a full transition to utf8? - metazet
  • Normal functions like substr do not work, you need to use mb_substr, well, similarly with other string functions, did not check everything :) - Ozim
  • If Ajax returns utf8, and the page is in windows-1251, then I will get a problem. The question was how to fix it better if the page cannot be changed. - KutaBeach
  • I answered you: [iconv] [1] [1]: ua.php.net/manual/en/book.iconv.php - Ozim
  • <b> OZIM </ b> - it is written that it will return, how can the receipt of an AJAX be processed by the server? O_o <br> Receive data and immediately pull into another script to overtake via iconv? : D - Zowie

JavaScript always operates (must operate, at least) with utf text