Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Making a html alert using ajax, sql and php

I am trying to make some code where a click of a SQL html button can display a different SQL table as a popup. I have already gotten the variable from the table to pass through using this:

echo "<td><a class='btn-floating btn-large waves-effect waves-light black' onclick='partSearch(".$product.")' value='display'><i class='material-icons'>search</i></a></td>";

The 'part search' code is as follows:

    <script type="text/javascript"> 
        function partSearch() {
            $.ajax({
            url: 'serv.php?id=<?php echo $product ?>',
            type: 'GET',
            success: function(result){
                var obj = jQuery.parseJSON(result)
                alert(obj)
            }
            })
        }
    </script> 

Even though the variable is passed through to 'serv.php', I can't manage to get the sql data to be returned as a popup using alert. All I get is either nothing or [object, Object]. This is the SQL/php code:

<?php   
    include 'includes/dbh.inc.php';
    $id = $_GET['id'];
    $result = mysqli_query($conn,"SELECT * FROM pr WHERE product_ID='".$id."'");// test this

    $rows = array();
    while($r = mysqli_fetch_assoc($result)){
        $rows[] = $r;
    }


    echo json_encode($rows);
    ?>  

Any help is appriciated

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

    <script type="text/javascript"> 
            function partSearch() {
                var product_id = "<?php echo $product; ?>";
                $.ajax({
                    url: 'serv.php?id=product_id',
                    type: 'GET',
                    success: function(result){
                      alert(result);
                    }
                })
            }
   </script> 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda