Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created May 26, 2015 12:36
Show Gist options
  • Save alexandreaquiles/6046be211c8357ad60f6 to your computer and use it in GitHub Desktop.
Save alexandreaquiles/6046be211c8357ad60f6 to your computer and use it in GitHub Desktop.
Consulta a cep usando AJAX com jQuery.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<script>
function consulta(){
var cep = $("#cep").val();
var url = "http://cep.correiocontrol.com.br/"+cep+".json";
$.get(url, function(dados){
var endereco = dados.logradouro + "-" + dados.bairro;
$("#resultado").html(endereco);
}, "json");
}
</script>
<input id="cep">
<button onclick="consulta();">Consultar</button>
<p id="resultado"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment