所以我正在用java-mysql做一个销售系统,并且几乎所有东西都可以正常工作。我的问题之一是,例如,当我想出售某物时,首先我要求提供收据的类型,日期和购买者(模态中的所有物品),然后我发送并完成工作,立即关闭第一个模态,显示第二个模态将产品放在上,并输入一定的费用。这是问题所在,当我单击按钮时,我发送该信息并返回更多变量,以同一模式填充表格中的表格,但此表格未显示任何内容。我试图使用console.log检查是否有数据,并且似乎在那里,所以请确定该怎么做。
此处的代码:
模式:
<div class="modal fade" id="detalleventasmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Nueva venta</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class=".col-6 .col-md-4 m">
<div class="container">
<div class="form-group">
<label for="a">Productos:</label>
<select id="selecpro" class="form-control">
<option value="null">Seleccionar</option>
</select>
</div>
<div class="form-group">
<label for="a">Cantidad:</label> <input type="text"
class="form-control" name="cant_venta" id="cantidad_venta">
<button type="button" class="btn btn-primary" id="botonaddproducto">Agregar Producto</button>
</div>
<table class="table table-borderless" id="tabladetalleproductos">
<tbody>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Categoria</th>
<th scope="col">Producto</th>
<th scope="col">Precio</th>
<th scope="col">Cantidad</th>
<th scope="col">Acción</th>
</tr>
</thead>
</tbody>
</table>
<div class="form-group">
<label for="a">Precio Total:</label><label id="preciototallbl"></label>
<input type="hidden" name="iddetalleventa" id="iddetalleventa" value="0">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
<button type="button" id="botondetalleventa" class="btn btn-primary" data-dismiss="modal">Enviar</button>
</div>
</div>
</div>
</div>
jQuery:
$("#botonaddproducto").click(function(){
var idpro= $("#selecpro").val();
var cant= $("#cantidad_venta").val();
console.log(idpro);
var i, c =1;
$.post("pc",{idpro:idpro,opc:4},function(data){
console.log(data);
var d = JSON.parse(data);
$('#tabladetalleproductos tbody').empty();
for(i=0;i<d.length;i++){
$("#tabladetalleproductos tbody").append("<tr><td style='color:blue'>"+c+"</td><td>"+d[i].idcategoria+"</td><td>"+d[i].nom_producto+"</td><td>"+d[i].precio+
"</td><td>"+cant+"</td><td><a href='#' style='color:red' onclick=''><i class='far fa-trash-alt'></i></a></td></tr>")
c++;
}
});
});
控制器:
PrintWriter out= response.getWriter();
int op = Integer.parseInt(request.getParameter("opc"));
switch (op) {
case 1:
pr.create(new Producto(0, Integer.parseInt(request.getParameter("idcategoria")),
request.getParameter("pro"), Double.parseDouble(request.getParameter("pre")),
Integer.parseInt(request.getParameter("cant"))));
out.println("Registro guardado correctamente..!");
break;
case 2:
out.println(g.toJson(pr.readAll()));
break;
case 3:
out.println(g.toJson(pr.delete(Integer.parseInt(request.getParameter("id")))));
break;
case 4:
out.println(g.toJson(pr.read(Integer.parseInt(request.getParameter("idpro")))));
break;
}