Error jQuery 500 when executing a GET

0

I have a small script that calls a PHP file but it does not work for me, it throws 500 error by the Chrome console ...

The idea is that when you select an element in a textlist, then execute the PHP code and print it inside a table that has its respective ID ... the script is:

<script type="text/javascript">
  $(document).ready(function(){
    $("#codigo").change(function(){
      $.get("admin/actions/checkbox_mantenimiento.php","codigo="+$("#codigo").val(), function(data){
        $("#tipos_mant").html(data);
        console.log(data);
      });
    });
  });
</script>

And the PHP is as follows:

<?php

include("config.php");

if(isset($_GET['codigo']))
{
    $codigoequipo=$_GET['codigo'];

    if($codigoequipo=="") {
        echo "Ningún equipo seleccionado.";
    }

    else {  
        $consulequipo = "SELECT * FROM maquinarias WHERE serialequipo = '$codigoequipo'";
        $consultipos = "SELECT * FROM mantenimiento WHERE codigo = '$codigoequipo'";

        $equipo = $bd->consulta($consulequipo);
        $tipos = $bd->consulta($consultipos);

        if ($rowtipos = $tipos->fetch_assoc() && $rowequipo = $equipo->fetch_assoc()) {
            $cantidadcb = $rowtipos['nro_tipos'];

            $checkboxes = while ($trigger < $cantidadcb) {
                echo "
                    <tr>
                        <td width=\"50%\">
                            <input class=\"form-control\" type=\"checkbox\" value=\"".$rowtipos['tipo'.$trigger]."required name=\"op_".$trigger."\">
                        </td>
                    </tr>";
                $trigger++;
            }

            echo "
                <form role=\"form\" action=\"?admin=mperiod&crearperiod=crearperiod\" method=\"post\" enctype=\"multipart/form-data\">
                    <thead>
                        <tr>
                            <th>Código</th>
                        </tr>
                    </thead>

                    <tbody>
                        <tr colspan=\"2\" width=\"50%\">
                            <td>
                                <input type=\"text\" class+\"form-control\" value=\"".$rowequipo['serialequipo']."\" name=\"codigo\" readonly required>
                            </td>
                        </tr>
                    <tbody>

                    <thead>
                        <tr>
                            <th>Tipos de Mantenimiento Asociados</th>
                        <tr>
                    <thead>

                    <tbody>
                        ".$checkboxes."
                    <tbody>
                        <tr> 
                            <td width=\"100%\" colspan=\"2\"><center>
                                <button type=\"submit\" class=\"btn btn-primary btn-lg\" name=\"lugarguardar\" value=\"Guardar\">Registrar</button></center>
                            </td>
                        </tr>
                    </tbody>
                </form>";
        }
    }
}
?>

If you need something additional I am ready to provide what is necessary. Thanks in advance for everything.

    
asked by Ronet Chirinos 13.12.2018 в 05:14
source

1 answer

1

How strange that you escape all the double quotes. To not be doing it, I recommend you use simple quotes in the echo, it would be something like this

echo '<input type="text" class="form-control" 
      value="'.$rowequipo['serialequipo'].'" name="codigo" readonly required>';

Now this is kind of weird, I do not see the variable $trigger in your code declared

$checkboxes = while ($trigger < $cantidadcb) {
                echo "
                    <tr>
                        <td width=\"50%\">
                            <input class=\"form-control\" type=\"checkbox\" value=\"".$rowtipos['tipo'.$trigger]."required name=\"op_".$trigger."\">
                        </td>
                    </tr>";
                $trigger++;
            }

I have never done it that way, but I think it can be your salvation this

$trigger = 0;
$checkboxes = '';
while ($trigger < $cantidadcb) {
                $checkboxes.= "
                    <tr>
                        <td width=\"50%\">
                            <input class=\"form-control\" type=\"checkbox\" value=\"".$rowtipos['tipo'.$trigger]."required name=\"op_".$trigger."\">
                        </td>
                    </tr>";
                $trigger++;
            }

Maybe that's how you get out of the error that is most likely. If not, then activate the error trace at the beginning of your script as follows

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include("config.php");

if(isset($_GET['codigo']))
{
   ...
}

In the preview of the Chrome console, you will be sent again the error 500 but with the detail of where you were wrong

    
answered by 13.12.2018 в 05:39