【发布时间】:2026-02-12 07:05:02
【问题描述】:
我必须用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 问题,但是 javascript 崩溃了,它消除了 ajax 函数并且它工作得很好,问题是 php ,并且控制台没有给我php的错误
-
我没有看到任何 javascript
-
function order(e, c){ $.ajax({ url: 'order.php', type: 'POST', dataType: 'html', data: {e: e, c: c}, }) .done(function(r){ $('#order').html(r); }) .fail(function(){ console.log("error"); }) } order(1, 5); -
javascript 崩溃是什么意思?