Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda