Passing variable value by $.post

Asked

Viewed 268 times

0

I am trying to however not know how to send the value of select to the page.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pedido de teste</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
</head>

<body>

<div>
    <h1>Produto de Teste</h1>
    <p>Valor: 299,00</p>
    <button onclick="enviaPagseguro();">Comprar</button><br />
    <img src="loading.gif" id="loading" style="visibility: hidden">
</div>

<form id="comprar" action="https://pagseguro.uol.com.br/v2/checkout/payment.html" method="post" onsubmit="PagSeguroLightbox(this); return false;">
    <input type="hidden" name="code" id="code" value="" />
    <select name="itemAmount1">
        <option value="10.00">Tentar obter 1000 Donate Points</option>
        <option value="30.00">Tentar obter 3500 Donate Points</option>
        <option value="50.00">Tentar obter 6000 Donate Points</option>
        <option value="80.00">Tentar obter 9500 Donate Points</option>
        <option value="150.00">Tentar obter 20000 Donate Points</option>
        <option value="225.00">Tentar obter 30000 Donate Points</option>
    </select>

</form>

<script type="text/javascript" src="https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.lightbox.js"></script>

<script>
    function enviaPagseguro(codigo){

        $.post('salvarpedido.php','',function(idPedido){

            $('#loading').css("visibility","visible");

            $.post('pagseguro.php',{idPedido: idPedido},function(data){

                $('#code').val(data);
                $('#comprar').submit();

                $('#loading').css("visibility","hidden");
            })
        })
    }
</script>

</body>
</html>

Someone?

2 answers

1


You can take the value of select with the code:

$("select[name='itemAmount1']").val();
  • But how would you send to pagseguro.php?

  • Here {idPedido: idPedido} I know that passes idPedido more as I pass itemAmount1?

  • ,itemAmount1: $("select[name='itemAmount1']").val()

  • $.post('pagseguro.php',{idPedido: idPedido,itemAmount1: $("select[name='itemAmount1']"). val()},Function(date) Picked up.

0

Your code is right, just add the post variable in itemAmount1.

On the page pagseguro.php:

$data['itemAmount1'] = $_POST['itemAmount1'];

The post parameter name must be the same as the select name.

Browser other questions tagged

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