我看到了这个问题。在 Chrome/Safari 中,被设置为包含一些特殊字符(即西类牙波浪号“i”)的内容的 Ajax 响应不会被正确解释。
这个问题用这里的例子完美总结:
I tried Firefox and IE and both works fine. Only Chrome is not displaying web page correctly. This is the URL: http://maixner.eu/#bio As you can see, some characters are wrong. This line: 2012 - Muzeum modernÃho umÄ›nÃ, Olomouc, Czech Republic Should be: 2012 - Muzeum moderního umění, Olomouc, Czech Republic
Dev details: 1) There is index.html page with javascript file, which loads data via AJAX (calls PHP file) 2) index.html file has content-type set to UTF-8 3) all files are UTF-8 encoded 4) javascript injects innerHTML using XMLHttpRequest class with responseText 5) php file has header('Content-type: text/html;charset=UTF-8"');
和这里:
Have similar (or same) problem, but with spanish characters. I have set Apache to use UTF-8 I have set php header('Content-Type: text/html; charset=utf-8'); I have set html I have set html But Chorme (only Chrome, FF, IE, etc work ok) shows this:
[Post headers] ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 ... [Some random post value from the form] ------WebKitFormBoundary0wi0NAscQiUkF2hJ Content-Disposition: form-data; name="s_name" OxÃgeno 100.4 FM Bogotá <-- characters are wrong! should read: Oxígeno 100.4 FM Bogotá
Original Post
最佳答案
我有同样的问题。
基本上,就我而言,这是因为浏览器发送的请求 header 。
chrome 发送:内容类型:应用程序/x-www-form-urlencoded,只有 .
firefox 发送:Content-Type:application/x-www-form-urlencoded;字符集=UTF-8
如果没有 charset=UTF-8,服务器默认为 ISO,并错误地解码。
关于ajax - Chrome Ajax 响应中的 UTF-8 编码出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555162/