0
I need you to fill out the input
CPF/CNPJ Bring me the customer’s zip code and city that is automatically registered in the bank after losing the focus of the CPF/CNPJ input.
The consultation at the bank is not a problem is already ok just would like to know how to return the information within the input
cep - city (there will be more inputs these are an example).
So far only managed to return some sample data within a div.
Form
<form method="POST" action="" id="formulario">
<legend><b>Dados do Destinatário da Entrega</b></legend>
<label>Nome<br>
<input type="text" name="nome" id="nome">
</label>
<label>CPF/CNPJ<br>
<input type="text" name="cpf" id="cpf" required>
</label>
<label>CEP<br>
<input type="text" name="cep" id="cep">
</label>
<label>Cidade<br>
<input type="text" name="cidade" id="cidade">
</label>
</form>
<div class="recebeDados"></div>
<script>
$(document).ready(function () {
$('#formulario').submit(function() {
var dados = $('#formulario').serialize();
$.ajax({
type : 'POST',
url : 'precontroller/precontroller_valida_form.php',
data: dados,
success : function(data){
$('.recebeDados').html(data);
}
});
return false;
});
});
</script>
precontroller_valida_form.php
<?php
if (isset($_POST) && !empty($_POST)){
//Consulta no banco
echo $_POST['nome'];
}
?>
You would have to return a JSON
{"cep" : "cep do cara", "cidade" : "cidade do cara"}
and then send these values to the respective inputs. No Case would have to do an AJAX for this inside a callback of a Blur event in the field of CPF/ CNPJ.– Sam
I get it, can you give me an example in this context ? I don’t use much AJAX.
– KevinF