用https上的Charset UTF-8打印文本无法正确打印字符



我的网站带有https,当我尝试用ajax获取数据时,给了我错误的字符。我的charset是:meta content =" text/html; charset = utf-8"

  $.ajax({
        type:'get',
        url:'{!!URL::to('findCiudad')!!}',
        data:{'departamento':departamento},
        beforeSend : function(xhr) {
            xhr.setRequestHeader('Accept', "text/html; charset=utf-8");
        },
        success:function(data){
           op1+='<option value="0" selected disabled>Select City</option>';
                for(var i=0;i<data.length;i++){
                    op1+='<option value="'+data[i].local+'">'+data[i].desc+'</option>';
            }
           $("#ciudad_entrega").html(" ");
           $("#ciudad_entrega").append(op1);
        },
        error:function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });

这是我的控制器,用utf8_encode

转换结果
    $result = array();
    foreach ($datos as $key => $dato) {
        //return $key;
        array_push($result, 
            array(
                'localidad' => utf8_encode($dato->localidad),
                'descripcion' => utf8_encode($dato->descripcion),
                'oficina' => utf8_encode($dato->oficina),
                'cod_departamento' => utf8_encode($dato->cod_departamento)
            )
        );
    }
    return response()->json($result, 200, ['Content-type'=> 'application/json; charset=utf-8']);

我已经解决了,您必须转换:mb_convert_encoding()

mb_convert_encoding($ dato-> desc,'utf-8','utf-8');

最新更新