Skip to content

Instantly share code, notes, and snippets.

@raisiqueira
Created April 13, 2015 13:30
Show Gist options
  • Save raisiqueira/50520b4b87d82ca4944a to your computer and use it in GitHub Desktop.
Save raisiqueira/50520b4b87d82ca4944a to your computer and use it in GitHub Desktop.
Javascript para retornar as cidades em ajax
$(function(){
$('#estados').change(function(){
if( $(this).val() ) {
$('#cidades').hide();
$('.carregando').show();
$.getJSON('{{site_url}}/cadastro/cidades?pesquisa=',{cod_estados: $(this).val(), ajax: 'true'}, function(j){
var options = '<option value=""></option>';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].cod_cidades + '">' + j[i].nome + '</option>';
}
$('#cod_cidades').html(options).show();
$('.carregando').hide();
});
} else {
$('#cidades').html('<option value="">– Escolha um estado –</option>');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment