DarkReaper Posted September 3, 2006 Share Posted September 3, 2006 Hello i am having a problem with ajax and php encodings ... i have a string encoded in cp1251 in a php variable, i save it to a file (using ajax and php), then with ajax i read it from the file and display it ... but only screwed up characters appears ... The strangest thing is that if i type a message (input box, again cp1251 encoding) and then handle it to be saved to a file and display it, everything is okay ...Do you have any ideas why is this happening? Quote Link to comment Share on other sites More sharing options...
expertsystems Posted September 5, 2006 Share Posted September 5, 2006 Hi,That's one of the drawbacks of Ajax. Whenever you send any data with xmlhttprequest object, it's automatically converted into UTF-8 and when received it's UTF-8 encoded. I had a similar problem. I feel there is no solution to it than again converting it to your desired encoding via PHP. On MSDN I had read that Microsoft is thinking of resolving this issue in future release of IE. Let's see when it happensRegardsRahul Quote Link to comment Share on other sites More sharing options...
DarkReaper Posted September 11, 2006 Author Share Posted September 11, 2006 How can i convert it again to my desired encoding? Example i send cp1251 encoding to ajax then when it converts it to utf8, i should convert it again to cp1251??? Am i right? Quote Link to comment Share on other sites More sharing options...
radalin Posted September 12, 2006 Share Posted September 12, 2006 The best way is to pass your total encoding to utf-8 which supports most of the characters.But instead of working with encodings try replacing problematic characters with html entities. This had solved my character encoding problem from xmlhttprequest thing. In longer textes it slows but 1 or 2 seconds is acceptable if everything is seen ok. Quote Link to comment Share on other sites More sharing options...
yaba Posted September 13, 2006 Share Posted September 13, 2006 I think your XMLHTTPRequest object send UTF-8 to your php script. In your php script then, you can convert it to your original encoding like this:[code=php:0]iconv("UTF-8","YOUR_ENCODING",$_GET['var'])[/code]and do whatever you want to do with it. When you need to return info from your php script, use XML if you need to return non-ASCII chars, like this:[code]header('Content-Type: application/xml');$out = '<?xml version="1.0" encoding="ORIGINAL_ENCODING?>' . "\r\n";$out .= '<report xml:lang="LANG_HERE"><message>'.$message.'</message></report>';echo $out;[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.