How to send ID written to variable in JSon return

0

I am doing insert using a class but I am not able to retrieve the last id registered, I need to save this id in a variable in json return because I need it to make a new registration, what I have is this :

require_once "../_classes/conexao_pdo.class.php";
require_once "../_classes/crud.class.php";

// Atribui uma conexão PDO   
$pdo = Conexao::getInstance();
$crud = Crud::getInstance($pdo, 'dvsMalote');

// INSERT
$crud = $pdo->prepare("INSERT INTO dvsMalote ( NumeroBolsa, IdUnicoopRemetente, IdUnicoopDestinatario, DataHoraEnvio, IdUsuarioEnvio, Estado  ) VALUES (?, ?, ?, ?, ?, ?)");
$crud->bindParam(1, $Bolsa, PDO::PARAM_INT);
$crud->bindParam(2, $UnicoopRemetente , PDO::PARAM_INT);
$crud->bindParam(3, $UnicoopDestinatario , PDO::PARAM_INT);
$crud->bindParam(4, $DataHoraEnvio , PDO::PARAM_STR);
$crud->bindParam(5, $Matricula , PDO::PARAM_INT);
$crud->bindParam(6, $Estado , PDO::PARAM_STR);
$retorno = $crud->execute();    

// RECUPERANDO NumeroMalote
$mensId = $pdo->lastInsertId(); 

if ($retorno):
    $retorno = array('codigo' => 1, 'mensagem' => ' Registro inserido com sucesso');
    echo json_encode($retorno);
    exit();
else:
    $retorno = array('codigo' => 0, 'mensagem' => ' Erro ao inserir o registro' );
    echo json_encode($retorno);
    exit();
endif;

I can already retrieve id , now I'm not sure how to send this value to the call page, the call page that waits for the return message looks like this:

if (response.codigo == "1") {
    $("#msgInsert").html('×AVISO!  ' + response.mensagem  + '');
} else {
    $("#msgInsert").html('×ATENÇÃO!  ' + response.mensagem + '');
}

How can I send this id retrieved to it and place the value in a variable?

    
asked by anonymous 08.11.2017 / 18:36

0 answers