-
Notifications
You must be signed in to change notification settings - Fork 0
/
busca_cep.js
35 lines (33 loc) · 1.13 KB
/
busca_cep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$(document).ready( function() {
$('#txtCep').mask('99.999-999');
/* Executa a requisição quando o campo CEP perder o foco */
$('#txtCep').blur(function(){
/* Configura a requisição AJAX */
$.ajax({
url : 'busca_cep.php', /* URL que será chamada */
type : 'POST', /* Tipo da requisição */
data: 'cep=' + $('#txtCep').val(), /* dado que será enviado via POST */
dataType: 'json', /* Tipo de transmissão */
success: function(data){
if(data.sucesso == 1){
$('#txtLogradouro').val(data.rua);
$('#txtBairro').val(data.bairro);
$('#txtCidade').val(data.cidade);
$('#txtEstado').val(data.estado);
$('#txtNumero').focus();
}
}
});
return false;
});
$("#btnCancelar").click(function(){
$("#form_cep").reset();
});
});
$("#btnSalvar").click(function(){
if($("#txtCep").val() != '') {
alert('Cep consultado com sucesso!');
}else{
$('#txtCep').focus();
}
});