【问题标题】:How to get Response data character set in Ajax?如何在 Ajax 中获取响应数据字符集?
【发布时间】:2017-02-23 05:36:43
【问题描述】:

Ajax 请求:

$("button").click(function(){
    $.ajax({url: "demo.html", success: function(result){
        $("#div1").html(result);
    }});
});

这里 ajax 请求从 demo.html 文件中获取数据,然后结果变量包含响应数据。那么,如何检查字符集类型 结果变量中的数据。考虑demo.html 是 shift_jis。因此,在进行 ajax 请求时,响应数据字符集与 demo.html 字符集或 它设置为utf-8

【问题讨论】:

  • 读取响应头
  • 使用teleriks fiddler 向该网址发送请求并检查其标头

标签: javascript jquery ajax character-encoding shift-jis


【解决方案1】:

尝试使用 xhr 读取标题并读取标题的字符集,如下所示

$("button").click(function(){
    $.ajax({url: "demo.html", success: function(response,xhr,result){
    var cs = xhr.getResponseHeader("charset") ;
        $("#div1").html(result);
    }});
});

【讨论】:

    猜你喜欢
    • 2021-11-15
    • 2013-08-08
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 2015-06-01
    • 1970-01-01
    • 2012-02-22
    相关资源
    最近更新 更多