2023-01-14
buscaba como pasar de un objeto json a jquery y colocarlo en una tabla lo pude resolver asi:
en el archivo javascript
// CARGA DATOS VENTAS DEL DIA
function listarVentasDia(turno_id) {
$.ajax({
type: 'GET',
url: 'admin_ctrl.php?accion=listar_venta_seleccionada&turno_id=' + turno_id,
data: '',
success: function(datos) {
$.each(datos, function() {
$('#myTable > tbody').append(
'<tr>' +
'<td>' + this.venta_id + '</td>' +
'<td>' + this.venta_nombre_producto + '</td>' +
'<td>' + this.venta_nombre_proveedor + '</td>' +
'<td>' + this.venta_costo_producto + '</td>' +
'<td>' + this.venta_valor_venta + '</td>' +
'<td>' + this.venta_user_nombre + '</td>' +
'<td>' + this.venta_turno_id + '</td>' +
'</tr>'
);
});
el html
<div class="row">
<span>VENTAS REALIZADAS EN EL DIA</span>
<table class="table" id="myTable">
<thead>
<tr>
<td>ID</td>
<td>PRODUCTO</td>
<td>PROVEEDOR</td>
<td>PRECIO COSTO</td>
<td>PRECIO VENTA</td>
<td>VENDEDOR</td>
<td>UTILIDAD</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
y en el php:
switch ($_GET['accion']) {
case 'listar_venta_seleccionada':
// ENVIA LOS DATOS AL DATATABLES
$sql = "SELECT
VENTAS.venta_id,
VENTAS.venta_nombre_producto,
VENTAS.venta_nombre_proveedor,
VENTAS.venta_costo_producto,
VENTAS.venta_valor_venta,
USERS.user_nombre,
VENTAS.venta_utilidad,
VENTAS.turno_id
FROM VENTAS
INNER JOIN USERS
ON VENTAS.user_id=USERS.user_id
WHERE turno_id=$_GET[turno_id]
";
$stmt = $pdo -> prepare($sql);
$stmt -> execute();
$result = $stmt -> fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
break;
};