Store onclick values in the database

Asked

Viewed 129 times

0

Colleagues,

How do I get the value of a onclick and direct to another page. See below:

$('.value-plus').on('click', function(){    
    var lista = $('.invert > span');  
    $.each(lista, function(index,item){  
    valor = $(item).text();
    trocar = valor.replace(",",".");  

      e.preventDefault();
      var objeto = new Object();
      objeto.valor = trocar.toFixed(2);
      var dados= JSON.stringify(objeto);

     $.ajax({
         type: "GET",
         dataType: 'json',
         data: dados,
         url: "atualizar-carrinho.php",
         success: function(resposta){
           if (resposta) {
                alert("Sucesso!");
            } else {
                alert("Erro");
            }
        }
      });
     });
    });

In the update cart.php I’m taking it this way:

<?php
   $conexao = (conexao ao banco de dados);
   $novoValor = $_GET['valor'];
   mysqli_query($conexao,"INSERT INTO teste VALUES(null,'".$novoValor."')");
  • Serialize the list and send it on date! You can use as an example this answer here

  • what you are hoping to receive in the atualizar-carrinho.php? values separated by comma? objects?

  • Hello Andrepaulo. The objects. I need to take the variable change.

  • Hello Marconi. I made a change to my post based on the link you sent me, but it is not passing the value...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.