Created
April 13, 2015 13:30
-
-
Save raisiqueira/50520b4b87d82ca4944a to your computer and use it in GitHub Desktop.
Javascript para retornar as cidades em ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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