2
I have a form that searches and fills, via ajax, the name of the person and year of birth (in their respective fields), all this from the Cpf typed by the user.
It’s something like this:
Digite o CPF do usuário ______________ <button>BUSCAR DADOS</button>
NOME _________________________
DATA DE NSACIMENTO __________________
With this, two requests are made as follows:
$('#botao').click(function(){
//BUSCA NOME
$.get('buscar_nome.php?cpf='+$('#cpf').val(),
function(result) {
$('#nome').val(result);
});
//BUSCA DATA DE NASCIMENTO
$.get('buscar_data_nascimento.php?cpf='+$('#cpf').val(),
function(result) {
$('#datanascimento').val(result);
});
PHP pages are with the following logic:
search_name.php
$cpf = $_GET['cpf'];
$sq1 = select * from tabela where cpf = '$cpf';
$registro = myslq_fetch_array($sq1);
echo registro['nome'];
buscar_data_nascimento.php
$cpf = $_GET['cpf'];
$sq1 = select * from tabela where cpf = '$cpf';
$registro = myslq_fetch_array($sq1);
echo registro['datanascimento'];
It works perfectly, however, I would like to optimize the search of this data (name and date of birth) using only one request. I imagine I should use Array. How should I proceed?
you can use a JSON object tb face, it is interesting for the practicality, it has "indices" with name so it is easier to access in my design.
– Marcos Henrique