I have my website with https and when i try to get data with ajax, gave me wrong characters. my charset is: 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);
}
});
this is my controller, convert the result with 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']);