I can’t take table value and use in ajas

Asked

Viewed 37 times

0

You guys talking, Blz? I’m a beginner in php and have a table populated with while and need to use the value of a td in a select on another page returning in a modal. The structure I built works if I put the value manually in the script, but when I search directly from the table no information comes.

When I change Date: {expense: expense}, to Date: {expense: 4}, the data goes correctly to Div in Modal, otherwise only the headers appear.

The code is like this:

Index.html - TD

<td id="despesa"><?php echo $dados['cod_despesa']; ?></td>
<td id="janeiro" data-toggle="modal" data-id="1" data-target="#modal_detalhes"><?php echo $dados['janeiro']; ?></td>

Div - Modal

<div id="dados" class="modal-body modal-xs"></div>

Script

function janeiro(despesa)
        {
            var page = "analitico.php";
            $.ajax
                    ({
                        type: 'POST',
                        dataType: 'html',
                        url: page,
                        beforeSend: function () {
                            $("#dados").html("Carregando...");
                        },
                        data: {despesa: despesa},
                        success: function (msg)
                        {
                            $("#dados").html(msg);
                        }
                    });
        }
        $('#janeiro').click(function () {
            janeiro($("#despesa").val())
        });

Analytic.php

$sql_detalhe_janeiro = "select..";  $detalhe_fevereiro = mssql_query($sql_detalhe_fevereiro);

Modal table

<?php 

    while($dados = mssql_fetch_assoc($detalhe_janeiro)) {?>
    <tr>
        <td><?php echo $dados['DESCRICAO']; ?></td>
  • The method .val() is for <input>. Forehead to wear $("#despesa").text().

  • Speaking Sergio, blz? It worked, is bringing the data from my select but only brings the first expense of the table, so it is not

  • What do you mean? You want to send the entire table to the analytical file?

  • No, I will send only the cod_expense that will be used in another select in the analytic.php ( ..Where cod_expense = $cod_expense ). In the td where this information is put the id 'expense''.

1 answer

0

And if you do so?

<td id="despesa"><?php echo $dados['cod_despesa']; ?></td>
<td id="janeiro" data-toggle="modal" data-id="<?php echo $dados['cod_despesa']; ?>" data-target="#modal_detalhes"><?php echo $dados['janeiro']; ?></td>

Return your analytical as json

$('#janeiro').on('click', function () {
    var id   =     $(this).data('id');

    var page = "analitico.php";
        $.ajax
                ({
                    type: 'POST',
                    dataType: 'json',
                    url: page,
                    beforeSend: function () {
                        $("#dados").html("Carregando...");
                    },
                    data: {despesa: id},
                    success: function (msg)
                    {
                        $('#modal_detalhes').modal('show');
                    }
                });
});
  • So cod_expense does not go to analytic.php. returns a Boolean(false) in var_dump.

  • you added the command data-id="<?php echo $dados['cod_despesa']; ?>" month-line ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.