Search field value does not arrive in jquery

0

I have a form where you have an internal search and pagination in Jquery and PHP. The end result is this:

Pagingisworkingcorrectly,butwhenItypetheusername,thevaluegetsnullinjquery.HowcanIgetthevaluetypedbyjqueryinthesearchfieldandimplementthecodebelow:

Searchfield:

<formclass="" action="#!" method="post">
    <div class="input-group">
     <input type="text" name="Usuario" class="form-control" placeholder="Buscar por nome" id="usuario" aria-label="Buscar por nome">
     <div class="input-group-prepend">
     <button type="submit" class="input-group-text" style="cursor: pointer"><i class="fas fa-search"></i></button>
    </div>
    </div>
    </form>
    <span id="conteudo"></span>

Jquery

<script>
    var qnt_result_pg = 10;
    var pagina = 1;
    var busca = $("#usuario").val();
    $(document).ready(function () {
        listar_usuario(pagina, qnt_result_pg, busca);
    });
    function listar_usuario(pagina, qnt_result_pg, busca){
    var dados = {
            pagina: pagina,
    busca: busca,
            qnt_result_pg: qnt_result_pg
        }
        $.post('listar-pagamentos-pendentes.php', dados , function(retorna){
            $("#conteudo").html(retorna);
        });
    }
</script>

PHP (list-pending-payments.php)

$pagina = $_POST['pagina'];
$qnt_result_pg = $_POST['qnt_result_pg'];
$busca = $_POST["busca"];
echo $metodos->listarPendentes($pagina,$qnt_result_pg,$busca);

I understand that I have to get the click of the search button, but I'm not sure how to implement the above code without impacting the pagination. I would like to point out that the problem is not in PHP but in Jquery because I can not get the value typed in the search field and play into the list-pending-payments.php page where I make the paging.

    
asked by anonymous 19.12.2018 / 12:16

1 answer

0

I was able to solve it as follows. Includes the POST value in PHP within Jquery. Please feel free to correct:

var busca = "<?php echo $_POST["Usuario"]; ?>";
    
19.12.2018 / 12:47