Skip to content

Instantly share code, notes, and snippets.

@macedo
Created December 28, 2012 02:56
Show Gist options
  • Save macedo/4394072 to your computer and use it in GitHub Desktop.
Save macedo/4394072 to your computer and use it in GitHub Desktop.
Fill brazilian addresses from cep
$('.cep').blur(function() {
var cep = $(this).attr('value').replace(/-/, '');
$.ajax({
url : 'http://cep.correiocontrol.com.br/' + cep + '.json',
dataType: 'json',
success: function(data) {
console.log(data);
$('#address').attr('value', data.logradouro);
$('#neighborhood').attr('value', data.bairro);
$('#city').attr('value', data.localidade);
$('#state').attr('value', data.uf);
},
error: function(data) {}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment