Hello. At the moment, I am making a website on which, using AJAX, а передается GET-запрос PHP-Файлу и этот файл возвращает результат. Это дело осуществляется при регистрации, вводе данных в поля формы и динамической проверке этих самых данных. В форме надо указать, к примеру, имя на русском языке. Имя отсылается Get-запросом к обработчику, но...вместо введенного в форму имени ajax а передается GET-запрос PHP-Файлу и этот файл возвращает результат. Это дело осуществляется при регистрации, вводе данных в поля формы и динамической проверке этих самых данных. В форме надо указать, к примеру, имя на русском языке. Имя отсылается Get-запросом к обработчику, но...вместо введенного в форму имени ajax а передается GET-запрос PHP-Файлу и этот файл возвращает результат. Это дело осуществляется при регистрации, вводе данных в поля формы и динамической проверке этих самых данных. В форме надо указать, к примеру, имя на русском языке. Имя отсылается Get-запросом к обработчику, но...вместо введенного в форму имени ajax , question marks are sent. And this is only in IE, that is, in all other browsers such garbage is not observed. All files are in UTF-8 encoding. Already tried a lot of things: specify the encoding in HTACCESS, s mb_string, but nothing with this stupid IE does not work ... please help.


Here, the problem is rather in the coding of the GET request, rather than in the coding of the site itself ...

  • Try to set the encoding in IE on UTF-8 itself - johniek_comp
  • he will be able to - and here is why I should do this? it is easier for him to leave the site :). On the topic - maybe in the template something upset something wrong? - Baran
  • nifiga itself) and that, each user to ask "Please set the encoding of your fucking IE in UTF-8, and then our site is not provided for IE"? - AseN 1:01 pm
  • @Darix, well, I do not even know ... but what for example? - AseN
  • the encoding in <meta> ^^ I forgot a little :) I did it a couple of times; D did the whole site on UTF and in the template was cp1251 and then was very surprised when I saw spells instead of letters in an incomprehensible language: D - Baran

1 answer 1

Hmm ... This is a topic, as I understand it, eternal and the most important thing is that there is no universal way. Everyone has some hidden "underwater stone". Try each or all of the following:

a) Set the locale

 setlocale(LC_CTYPE, array('ru_RU.CP1251', "ru_RU","ru","rus_RUS")); 

b) In the .htaccess line

 AddDefaultCharset UTF-8 

c) After connecting to the database:

 mysql_query('SET NAMES "utf8"'); 

d) Accepting a parameter or when responding is to recode data:

 $data= iconv("cp1251","UTF-8",$data); 

You can even do a simple check on the encoding before

 if (!preg_match('//u', $data)) { $data= iconv("cp1251","UTF-8",$data); } 

e) On the server side to register:

 header("Content-type: text/html; charset=utf-8"); 

and someone can work the other way around

 header("Content-type: text/html; charset=windows-1251"); 
  • Thank you for answering. I already thought that the encoding is something very complicated ... I tried two basic conversion methods - setlocale, iconv and AddDefaultCharset UTF-8. As a result, iconv somehow worked, but it worked so that everything in IE seems to be transforming normally, but in Chrome, Opera, Mozilla - it sucks, nothing happened ... maybe this is a problem in the encoding of my ajax GET request? What do you think? - AseN
  • I do not exclude. Perhaps the encoding must be converted already when sending data via ajax. By the way, I met a VERY mysterious way to solve the problem. I did not check it myself, but let it be crazy, but the option: <script src = "example.js" charset = "utf-8"> </ script> - Deonis
  • Oh, thank you so much for such an excellent article on Habré !!! May God bless the author of this article. The whole thing turned out to be in the encoding of the sent data by the JS-function "encodeURIComponen" - I simply did not use it ... thank you once again! PS As you only seek out all these articles =) - AseN
  • A rhetorical question;) - Deonis
  • Anyway, you helped me a lot with this article;) - AseN