0
I would like to know how I make a request via ajax in real time, basically it is to popular a select of cities, more when I have run the code his modal simply does not open, follow the code to analyze.
in the controller
$id = $_POST;
$query = $this->db->query(" SELECT * FROM estados ")->result();
$query_cidades = $this->db->query(" SELECT * FROM cidades WHERE cidades.cod_estado = $id")->result();
$data = [
'revendedor' => Model\Revendedores::find($cod_revendedor),
"estados" => $query,
"cidades" => $query_cidades
];
$this->load->view('revendedores/_form', $data);
in the view
$('.escolha').on('click', function(){
var id_box = $( this ).data('id-box');
$.ajax({
url: "sua url",
method: "POST",
dataType: "json",
data:{
id : id_box,
}
}).done(function( data ) {
$('.escolha').html(data.id);
});
});
vc already has an error in the first line, you are not getting the id of the post $id = (int)$_POST['id'];
– user1811893
thank you I will test here, put the resolution ok
– Aminadabe dos Santos da Silva