Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Ajax中获取响应数据字符集?_Javascript_Jquery_Ajax_Character Encoding_Shift Jis - Fatal编程技术网

Javascript 如何在Ajax中获取响应数据字符集?

Javascript 如何在Ajax中获取响应数据字符集?,javascript,jquery,ajax,character-encoding,shift-jis,Javascript,Jquery,Ajax,Character Encoding,Shift Jis,Ajax请求: $("button").click(function(){ $.ajax({url: "demo.html", success: function(result){ $("#div1").html(result); }}); }); 这里,ajax请求从demo.html文件获取数据,然后结果变量包含响应数据。那么,如何检查 结果变量中的数据。考虑 demo。HTML是SHIFTTYJIS。因此,在执行ajax请求时,响应数据字符集与demo.h

Ajax请求:

$("button").click(function(){
    $.ajax({url: "demo.html", success: function(result){
        $("#div1").html(result);
    }});
});
这里,ajax请求从demo.html文件获取数据,然后结果变量包含响应数据。那么,如何检查 结果变量中的数据。考虑<代码> demo。HTML<代码>是SHIFTTYJIS。因此,在执行ajax请求时,响应数据字符集与
demo.html
字符集或
它设置为
utf-8

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

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

阅读响应标题。使用
teleriks fiddler
向该url发送请求并检查其标题