XHR请求使用Chrome编码,在Safari中可以正常工作 [英] XHR request garbles encoding in Chrome, works fine in Safari
问题描述
以下代码在Chrome中显示it,但在Safari中为it。
The following code POSTs "it’s" in Chrome, but "it’s" in Safari.
invocation = new XMLHttpRequest()
invocation.open('POST', 'https://example.herokuapp.com/content/24/nl/123')
invocation.setRequestHeader('Content-Type', 'text/plain; charset=UTF-8');
invocation.send('{"data":"it’s"}')
我是否说服Chrome发布使用UTF-8?
How do I convince Chrome to post using UTF-8?
推荐答案
确保设置响应标头
Content-Type: text/html; charset=UTF-8
还在 https://example.herokuapp .com / content / 24 / nl / 123
目标页面,不只是在网站上(请求页面)。还要检查任何数据源(包括目标本身)的编码是否在UTF-8中。
also on the https://example.herokuapp.com/content/24/nl/123
target page, not just on the website (the request page). Also check if the encoding of any data source (including the target itself) is in UTF-8.
根据我测试,乱码编码只来自路径上的字符集不兼容性
As far as I have tested, the garbled encoding comes only from the charset incompatibilities on the path
client encoding- client request- server encoding- server data- server response
注意:如果您的网络服务器运行在PHP上,可以使用 header 作为响应头。如果由于某种原因无法设置标题,请使用 iconv 进行转换从您的字符集到UTF-8的响应。
Note: if your web server runs on PHP, you can use header for response header. If you can not set the header for some reason, use iconv to convert the response from your charset to UTF-8.
这篇关于XHR请求使用Chrome编码,在Safari中可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!