UTF-8 encoding does not meet Chrome Ajax requirements

I see this problem. In Chrome / Safari, the Ajax response, which is set as content containing some special characters (for example, the Spanish tilde "i"), is not interpreted correctly.

This problem sums up nicely with the example here:

I tried Firefox and IE, and both work fine. Only Chrome doesn’t display the webpage correctly. This is the URL: http://maixner.eu/#bio As you can see, some characters are mistaken. This line: 2012 - Muzeum modernÃho umÄ> nÃ, Olomouc, Czech Republic Should be: 2012 - Muzeum moderního umění, Olomouc, Czech Republic

Developer Details: 1) There is an index.html page with a javascript file that loads data through AJAX (calls the PHP file) 2) the index.html file has the content type set to UTF-8 3) all files are encoded in UTF-8 4 ) javascript inserts innerHTML using the XMLHttpRequest class with responseText 5) the php file has a header ('Content-type: text / html; charset = UTF-8 "');

And here:

Have a similar (or the same) problem, but with Spanish characters. I installed Apache to use UTF-8 I set the php header ("Content-Type: text / html; charset = utf-8"); I installed html I installed html But Chorme (only Chrome, FF, IE, etc. Works fine) shows the following:

[Message headers] ... Accept-Charset: ISO-8859-1, utf-8; q = 0.7, *; q = 0.3 ... [Some random value from the form] ------ WebKitFormBoundary0wi0NAscQiUkF2hJ Content-Disposition: form-data; name = "s_name" OxÃgeno 100.4 FM Bogotá - characters are wrong! read: Oxígeno 100.4 FM Bogotá

Original post

+4
source share
2 answers

I had the same problem.

Basically, in my case, this is due to the request header sent by the browser.

chrome sends: Content-Type: application / x-www-form-urlencoded, only .
firefox sends: Content-Type: application / x-www-form-urlencoded; encoding = UTF-8

Without charset = UTF-8, the server uses ISO by default and decodes it incorrectly.

+3
source

In the php header function you have an extra "before closing the line. It should be

<?php header('Content-type: text/html; charset=utf-8'); 
0
source

Source: https://habr.com/ru/post/1412033/


All Articles