且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JavaScript中显示带重音符号的字符

更新时间:2023-02-26 09:24:07

要详细介绍@georg的帮助我解决此问题的建议:

To give more detail to @georg 's advice that helped me solve this issue:

由于我无法更改服务器端脚本,因此我调整了代码.
我将ajax请求中的字符集更改为 ISO-8859-1 ,但是由于ajax的默认字符集为utf-8,因此我不得不覆盖该字符集与$.ajax.beforeSend:

Since I can't change the server side scripts, I adjusted the code on my side.
I changed the charset in my ajax request to ISO-8859-1, but since the default charset of ajax is utf-8, I had to override the charset with $.ajax.beforeSend:

$.ajax({
    url: url,
    type: "GET",
    dataType: "json",
    contentType: "application/json; charset=iso-8859-1",
    success: function(uri){
         alert("clintg test: " + JSON.stringify(uri));
    },
    beforeSend: function(jqXHR) {
        jqXHR.overrideMimeType('application/json;charset=iso-8859-1');
    }
}

以下是该问题的链接,该问题帮助我找出并覆盖了字符集: Jquery忽略编码ISO-8859-1

Here's a link to the question that helped me figure out and override the charset: Jquery ignores encoding ISO-8859-1