Pass the $ rfprod parameter when clicking on the line for a PHP program (POST method) [duplicate]

-4
<div id="posiciona">
    <table id="mostra_prod" cellpadding="1" cellspacing="3" bordercolor="#000000">
        <thead>
          <tr>
           <td align="right" bgcolor="#0a0a96">Aplicação</td>
           <td align="left"  bgcolor="#0a0a96">Referência</td> 
         </tr> 
        </thead>
        <tbody>
        <?php 
        $i=0;         
        while  ($row = mysqli_fetch_array($result_pd)) { 
            $rfprod  = $row['pro_referencia_produto'];
            $idref[] = $rfprod;  
            $i++;  
            $approd  = $row['pro_aplicacao_produto'];
            ?><tr><?php 
            echo "<td align='right' style='color: #cfcfd1; font-size:14px;'>".$approd."</td>";
            echo "<td style='color: #ffffff; font-size:11px; padding-top: 5px;'>".$rfprod."</td>";
            ?></tr><?php 
       }
       ?>   
        </tbody>      
    </table>
</div>

    
asked by anonymous 11.08.2017 / 15:55

1 answer

0

If I understand correctly, you want the user's reference code to be sent by POST when the user clicks on the item. Beauty. First I'll make some changes to your current code:

<div id="posiciona">
    <table id="mostra_prod" cellpadding="1" cellspacing="3" bordercolor="#000000">
        <thead>
          <tr>
           <td align="right" bgcolor="#0a0a96">Aplicação</td>
           <td align="left"  bgcolor="#0a0a96">Referência</td> 
         </tr> 
        </thead>
        <tbody>
        <?php 
        $i=0;         
        while  ($row = mysqli_fetch_array($result_pd)) { 
            $rfprod  = $row['pro_referencia_produto'];
            $idref[] = $rfprod;  
            $i++;  
            $approd  = $row['pro_aplicacao_produto'];
            ?><tr id="item"><?php 
            echo "<td align='right' style='color: #cfcfd1; font-size:14px;'>".$approd."</td>";
            echo "<td style='color: #ffffff; font-size:11px; padding-top: 5px;' id='referencia-item'>".$rfprod."</td>";
            ?></tr><?php 
       }
       ?>   
        </tbody>      
    </table>
</div>

What I did: I put an id in the "tr" parent so I could select it more easily, just like in the "td" of the reference. Now let's go to the js (jquery) part:

   $(function(){
        $("#item").click(function(){
    $.ajax({
    url: "referencia.php",
    type: post,
    data: ({referencia: $(this).find('#referencia-item').text()}),
    success: function(resposta){
    alert(resposta);
    }
    });
    });
    });

And create a file called "reference.php" Make your php on it! Example:

<?php
$referencia = $_POST['referencia'];
echo "O código de referência do produto clicado é ".$referencia;
?>

I hope you understand. Sorry for the bad formatting, I'm on my cell phone!

    
11.08.2017 / 19:16