do a jquery in a php to make a sentence without reloading page

0

I am creating a shopping cart but I have a problem, if I have several products chosen, then, I want that when I click on the button to delete some product because the price of the eliminated product is subtracted from the total amount, I have been told that in order not to recharge, I should do it in query.

<div class="producto">
    <center>
       <img src="./productos/<?php echo $datos[$i]['Imagen']; ?>"><br>
       <span><?php echo $datos[$i]['Nombre']; ?></span><br>
       <span>Precio: <?php echo $datos[$i]['Precio']; ?></span><br>
       <span>Cantidad:
          <input type="text" value="<?php echo $datos[$i]['Cantidad']; ?>"
data-precio="<?php echo $datos[$i]['Precio']; ?>"
           data-id="<?php echo $datos[$i]['Id']; ?>" class="cantidad">
       </span><br>
          <span class="subtotal">Subtotal:<?php echo $datos[$i]['Cantidad'] * $datos[$i]['Precio']; ?></span><br>

<a href="#" class="eliminar" data-id="<?php echo $datos[$i]['Id'] ?>">Eliminar</a>
    </center>
       </div>
            <?php
                $total = ($datos[$i]['Cantidad'] * $datos[$i]['Precio']) + $total;
}
    
asked by racxo 10.04.2017 в 17:17
source

1 answer

1

what you have to do is create a class that receives certain parameters, or you can make an intermediary to interpret and route them. Next step create an ajax that is executed in the action you want

$("#miDOM").on('click', function(event) {
    $.ajax({
        url: "miclase.php",
        type: "POST",
        data: val1: $("#primer_criterio"), val2: $("#segundo_criterio"), val3: $("#segundo_criterio"),
        success: function(resp){
            //aqui tratas tus datos que devolvio el php 
        }
    });
});

/*  PHP  */
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $val1 = $_POST['val1'];
    $val2 = $_POST['val2'];
    $val3 = $_POST['val3'];
    function miFuncion($val1,$val2,$val3){
        /*Aqui haces tus operaciones php*/
        /*Le haces un echo a los datos que quieres retornar al JS*/
        echo json_encode($result);
    }
}
?>

I hope it serves you

    
answered by 10.04.2017 / 21:44
source