Created
December 28, 2012 02:56
-
-
Save macedo/4394072 to your computer and use it in GitHub Desktop.
Fill brazilian addresses from cep
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
$('.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