Skip to content

Instantly share code, notes, and snippets.

@chr0nu5
Created July 21, 2014 01:58
Show Gist options
  • Save chr0nu5/e184b8bf62a3a046745f to your computer and use it in GitHub Desktop.
Save chr0nu5/e184b8bf62a3a046745f to your computer and use it in GitHub Desktop.
$('#cep').blur(function(){
var zip = $(this).val();
zip = zip.replace('-','').replace('.','');
$.ajax({
url:'http://cep.urldaapi.com.br/'+zip+'.json',
type: "GET",
cache: false,
dataType: "text",
crossDomain: true,
success:function(data){
data = JSON.parse(data);
$('#endereco').val(data.address);
$('#bairro').val(data.neighborhood);
$('#cidade').val(data.city);
$('select[name=uf]').find("option[value='" + data.state + "']").prop("selected", true);
$('select[name=uf]').parent().find('span').html(data.state);
$('.black').remove();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment