Jquery忽略编码ISO-8859-1 [英] Jquery ignores encoding ISO-8859-1

查看:134
本文介绍了Jquery忽略编码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

<meta charset="ISO-8859-1">

我通过

<script type="text/javascript" charset="ISO-8859-1" src="...

我通过JQuery Ajax Request发送此类信息(使用德语特殊字符'ö'和'ä'):

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
..

有什么?

当然,特殊字符编码错误(¶而不是ö)服务器不能理解我,我得到一个错误。 / p>

Of course the special characters are encoded wrong ("ö" instead of "ö") the server can't understand me and i get an error.

推荐答案

因为我有同样的问题,我会提供一个解决方案,为我工作。背景:Microsoft Excel太愚蠢,无法导出CSV文件在字符集UTF-8:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆