2
I’m working on a situation I haven’t been able to resolve in over two days straight. I have an AJAX that is requesting values for a controller to popular a select with cities. The request seems to be (no debug error), but however nothing comes in the return.
Javascript:
$(function() {
$('#selectEstado').change(function() {
var uf = $('#selectEstado').val();
$.ajax({
url: "busca/carregaCidades/" + uf,
dataType: "json",
success: function(data){
console.log(data);
}
});
});
});
Controller:
public function carregaCidades($uf)
{
$resultado = $this->busca_model->getCidades($uf);
return json_encode($resultado);
}
Model:
public function getCidades($uf)
{
$this->db->where('uf', $uf);
$dados = $this->db->get('tb_cidades')->result();
return $dados;
}
Even without any error in the console, the result of the request does not come. Thanks for the help
by chance, if you give a
var_dump
in$dados
inside the model comes something? Or if you give aecho $this->db->last_query();
to return the last query, when you run it in your direct bank, by phpmyadmin for example, give right wheel and return something?– Marcelo Diniz
Thank you for your answer, Marcelo! Had managed to solve, the problem was the return in the controller... I was returning PHP json to jquery, so I should have used echo instead of Return!
– Leandro Borges
Glad you solved your problem there, now cool is how you found the solution, answer how you solved so that future users tbm can benefit from your question.
– Marcelo Diniz