ajax - Chrome Ajax 响应中的 UTF-8 编码出错

标签 ajax google-chrome encoding safari webkit

我看到了这个问题。在 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/

相关文章:

unicode - Go 和 UTF-8 编码 - 转换是自动的吗?

jquery - AJAX 调用后无法使用 DOM 元素

javascript - 如何在 jquery/javascript 中使用 '.' 转义变量?

php - 带参数的 laravel ajax 操作 url

google-chrome - chrome使用什么图形库

javascript - Chrome 扩展程序 : webNavigation while limiting permissions scope

sorting - 由于编码问题,排序对象无法正确排序

javascript - 向页面传递 2 个或更多 URL 参数

javascript - 完整日历无法识别 Chrome 中日期字段上的点击事件?

python - 如何以与 python2 和 python3 一起使用的方式将 utf8 写入标准输出