Jquery 忽略编码 ISO-8859-1 [英] Jquery ignores encoding ISO-8859-1
问题描述
我有一个网站,它显然从字符串中删除了正确的编码 (ISO-8859-1) 并将其发送错误.
I have a website which apperently removes the correct encoding (ISO-8859-1) from a string and sends it wrong.
我在 HTML 中指定了这种编码
I have this encoding specified in my HTML
<meta charset="ISO-8859-1">
我通过
<script type="text/javascript" charset="ISO-8859-1" src="...
我像这样通过 JQuery Ajax 请求发送信息(带有德语特殊字符ö"和ä"):
I send for Information via JQuery Ajax Request like this (with german special character 'ö' and 'ä'):
$.ajax({
url: '..',
type: 'POST',
contentType: 'application/xml;charset=ISO-8859-1',
data: xmlRequest.html(),...
这被翻译成一个请求,在 chrome 开发者工具中,我在请求头中看到了这一点:
This is translated into a request and in the chrome developer tools I see this in the Request Header:
..
Content-Type: application/xml;charset=UTF-8
..
那里发生了什么?
当然,特殊字符编码错误(ö"而不是ö")服务器无法理解我,我收到错误.
Of course the special characters are encoded wrong ("ö" instead of "ö") the server can't understand me and i get an error.
推荐答案
因为我遇到了同样的问题,所以我会提供一个对我有用的解决方案.背景:Microsoft Excel 太笨了,无法以 UTF-8 字符集导出 CSV 文件:
Because I had the same problem, I'll provide a solution that worked for me. Background: Microsoft Excel is too stupid to export a CSV-File in charset UTF-8:
$.ajax({
url: '...',
contentType: 'Content-type: text/plain; charset=iso-8859-1',
// This is the imporant part!!!
beforeSend: function(jqXHR) {
jqXHR.overrideMimeType('text/html;charset=iso-8859-1');
}
});
这篇关于Jquery 忽略编码 ISO-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!