Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
The jQuery ajax does not send more than two values to post url

I have the following code to send the data via Jquery AJAX and notice that I have three values that need to be sent to the receiving file(Addtocart.php). The transmission and reception were good, but after a while I do not know why it no longer sends.. When one of the values is canceled and two remain, it sends.. but when three values are not sent.

ajax

<script >

$(document).ready(function() {
    $("#add-to-card").click(function() {
        var quantityq = $("#quantityq").val();
        var user = $("#user").val();
        var product__id = $("#product__id").val();
        $.ajax({
            url: 'Addtocart.php',
            method: 'POST',
            data: {
                quantityq: quantityq,
                user: user,
                product__id: product__id
            },
            success: function(data) {
                $('#result').html(data);
            }
        });
    });
});

</script>
<input step="1" min="1" max="50" name="quantityq" id="quantityq" value="1" title="Qty" class="input-text qty text" size="4" type="number">
<input type="hidden" name="user" id="user" value="72663">
<input type="hidden" name="product__id" id="product__id" value="4">
</div>
<button type="submit" id="add-to-card" class="btn sqaure_bt fll display-f">send</button>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is not clear what issue you are facing, as you didn't post an example that shows the issue clearly.

But Rather than binding to click event of the button, you should bind to submit event of the form. This way, client-side form validation will work correctly and your JS code will be a lot smaller.

<form id="myForm">
    <input step="1" min="1" max="50" name="quantityq" id="quantityq" value="1" title="Qty" class="input-text qty text" size="4" type="number">
    <input type="hidden" name="user" id="user" value="72663">
    <input type="hidden" name="product__id" id="product__id" value="4">
    <button type="submit" id="add-to-card" class="btn sqaure_bt fll display-f">send</button>
</form>



<script>

$(document).ready(function() {
    $("#myForm").submit(function(e) {
        e.preventDefault();
        let postData = $(this).serialize();
        $.ajax({
            url: 'Addtocart.php',
            method: 'POST',
            data: postData,
            success: function(data) {
                $('#result').html(data);
            }
        });
    });
});

</script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda