I can not get value from the table and use in ajas

0

Talk to people, blz? I am a beginner in php and I have a populated table with while and I need to use the value of a td in a select on another page returning in a modal. The structure I set up works by putting the value manually into the script, but when I look directly from the table there is no information at all.

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 looks 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())
        });

Analitico.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>
    
asked by anonymous 03.05.2017 / 19:02

1 answer

0

What if you do this?

<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 analytic 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');
                    }
                });
});
    
03.05.2017 / 20:56