weixin_33738578 2013-06-28 02:06 采纳率: 0%
浏览 14

Ajax发送错误的字符集

Ajax is sending to PHP

Ĺ asija-kabina

Instead of

Šasija-kabina

While I did declare the charset everwhere. In the head of the html file I've got this:

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

In the PHP file I've got this:

header('Content-Type: text/html; charset=latin2');

And this is my ajax function where "str" is a json array:

function updateField(str, id, prevvalue, value, vehicletype){
    $.ajax({
        type: "get",
        url: "inc/ajax/form_rest.php",
        data: { q:str, prevvalue:prevvalue, value:value, vehicletype:vehicletype },
        contentType: "application/json;charset=latin2",
        success: function(html) {
                    $('#'+id).html(html);
                }
        })
        .done(function(){
            $("#"+id).removeAttr("disabled");
            if($("#"+id+" option").length == 2){
                $("#"+id).val($("#"+id+" option:last-child").val()).change();
            }
            if($("#"+id+" option:last-child").val() == ""){
                $("#"+id).attr("disabled", "disabled");
            }
        });
}

Nevertheless I am getting the wrong output. Can anyone help me with this?

  • 写回答

2条回答 默认 最新

  • weixin_33747129 2013-06-28 02:10
    关注

    do you use an external javascript file for this?, I think you need also to set the character set for the inclusion of the javascript file

    <script src="myscripts.js" charset="latin2"></script>
    

    but I really recommend you to use UTF-8 both on server and client side scripts

    评论

报告相同问题?

悬赏问题

  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置