Pass data through POST with jquery

0

On one page I load a list of people with a checkbox next to each. I want to move all the people I've selected to the next page. I'm trying to do this:

In this code below I check who is selected and add in the nips variable. This code works perfectly.

$(".check:checked").each(function(){       
     if($(".check:checked").is(':checked')) 
     {          var nip = $(this).parent().next( 'td' ).text(); 
                nips.push(nip);   
     } 
  }) ;

Now in this code below I pass by post the nips variable (a vector). This code works in part.

$.ajax({             
       type: "POST",
       data: { nips:nips },             
       url: "../pdfporturma.php",
      dataType: "html"           
    });

Why partly? Because it does not point to the other page (../pdfporturma.php). By firebug I see the correct result, showing the items in the vector all right, but I can not get to that other page by uploading this data.

Resposta do firebug:
array(1) {
["nips"]=>
array(2) {
[0]=>
string(8) "85808610"
[1]=>
string(7) "6506224"
}
}

How do I do it? I already tried window.open but it does not pass the data.

    
asked by anonymous 24.09.2014 / 14:22

3 answers

1

Missing% marker%

        $.ajax({
        type: "tipo de requisição... GET ou POST",
        data: { seus dados },
        url: "sua página",
        success: function(data) { //Se a requisição retornar com sucesso, 
        //ou seja, se o arquivo existe, entre outros
                $('#').html(data); //Parte do seu 
                //HTML que voce define onde sera carregado o conteudo
                //PHP, por default eu uso uma div, mas da pra fazer em outros lugares
            }
        });
    
24.09.2014 / 14:36
1

You can look at the $ .ajax documentation. Here is an example of how I would do it!

  

Place the date: {nips: nips} as date: {'nips': nips} because it can treat as variable if you do not enclose it in quotation marks. / p>

$.ajax({
   url : '../pdfprotuna.php',
   dataType : 'html',
   type : 'POST',
   data : {'npis' : npis},
   beforeSend : function () {
         console.log('Carregando...');
   },
   success : function(retorno){
       alert(retorno);
   },
   error : function(a,b,c){
       alert('Erro: '+a[status]+' '+c);
   }
});
  

To pass data per post in a new window.

 <form name="teste" id="form_id_teste" action="teste.php" method="POST" target="BLANK">
     <input type="text" name="teste" value="Valor de teste" />
 </form>
 <script>
    $('#form_id_teste').submit();
 </script>
    
24.09.2014 / 14:59
1

If the checkboxes are inside a form, you can send the date as follows

data : $( "form" ).serialize(),

So you do not need that extra step to check the selected boxes before submitting the form.

    
24.09.2014 / 15:36