我必须形成一个单行表,其中包含由ID选择的mysql服务器的元素,该表运行完美(它显示在html文件中)。 我通过ajax函数在javascript文件中执行它,当我调用函数时,我的javascript崩溃了,请帮帮我
<?php
$conexion = mysqli_connect("localhost", "root", "", "db_dinagri");
$salida = "";
$query = "SELECT * FROM productos ORDER By ID";
$cantidad = 0;
//$Unidad = $fila['ProductU'];
if(isset($_POST['e']) && isset($_POST['c'])){
$q = $conexion->real_escape_string($_POST['e']);
$query = "SELECT ID, ProductN, ProductP, ProductU, ProductS FROM productos
WHERE ID LIKE '%".$q."%'";
$cantidad = $_POST['c'];
}
$resultado = $conexion->query($query);
$salida.="<table class='table table-sm' id='tabla' autofocus>
<thead class='thead-light'>
<tr>
<th scope='col'>Cantidad</th>
<th scope='col'>Unid.</th>
<th scope='col'>ARTICULO</th>
<th scope='col'>P. Unitario</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody>";
$fila = $resultado->fetch_assoc();
$salida.="<tr>
<td>".$cantidad."</td>
<td>".$fila['ProductU']."</td>
<td>".$fila['ProductN']."</td>
<td>".$fila['ProductP']."</td>
<td>40</td>
</tr>";
//if($resultado->num_rows > 0){
// $i
//for($i=1; $i<4; $i++){
// echo "hola";
//}
//while($fila = $resultado->fetch_assoc()){
//}
$salida.="</tbody</table>";
echo $salida;
$conexion->close();
?>
每当你对服务器进行ajax调用时,你都不会收到任何php错误的消息,因为它会成为内部问题,而在你的控制台日志中它会显示内部错误。最好一步一步地进行小规模检查,例如首先检查您传递的数据是否存在,查询是否正确或者等等。在您的情况下,查询是正确的,您的ajax调用对我来说是正确的猜测从查询检查中获取可能存在错误,也不需要在“。$ cantidad”的php var中使用“。”。将其更改为“$ cantidad”如果错误仍然存在,那么尝试使用while循环中的html代码形成所有结果,导致您的查询可能获取更多的那一行并更改ajax中的“dataType”打电话给“文字”。