Created
May 26, 2015 12:36
-
-
Save alexandreaquiles/6046be211c8357ad60f6 to your computer and use it in GitHub Desktop.
Consulta a cep usando AJAX com jQuery.
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
<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