下面的代码在Chrome中发布了“it?‘s™s”,但在Safari中发布了“it’s”。
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进行post?
发布于 2013-06-10 18:36:51
请确保设置响应头
Content-Type: text/html; charset=UTF-8也在https://example.herokuapp.com/content/24/nl/123目标页面上,而不仅仅是在网站(请求页面)上。还要检查任何数据源(包括目标本身)的编码是否为UTF-8。
据我测试,乱码只是由于path上的字符集不兼容造成的
client encoding- client request- server encoding- server data- server response注意:如果你的web服务器运行在PHP上,你可以使用header作为响应头。如果由于某些原因无法设置头部,可以使用iconv将响应从您的字符集转换为UTF-8。
https://stackoverflow.com/questions/17021425
复制相似问题