Send POST with Ajax and CodeIgniter

2

For almost 1 day I am facing a problem which until now can only be solved (making sure I was right) doing wrong, ie gambiarras.

I'm trying to create Transparent PagSeguro Checkout but I can not send POST with the Credit Card token and Sender Hash ...

   $(document).ready(function () {
                    PagSeguroDirectPayment.setSessionId("<?php echo $sessionId ?>")                     

                    var sender_hash = PagSeguroDirectPayment.getSenderHash();

                    var card_token = PagSeguroDirectPayment.createCardToken({
                        cardNumber: "4111111111111111",
                        brand: 'visa',
                        cvv: "123",
                        expirationMonth: "12",
                        expirationYear: "2030",
                        success: function (response) {

                        },
                        error: function (response) {
                            console.log(response);
                        }
                    });

                    $('input[name="pagar-cartao"]').click(function () {

                        event.preventDefault();

                        $.ajax({
                            url: '<?php echo base_url() . "donate/pay/" . $details->id?>',
                            type: 'POST',
                            data: 'cc_token=' + card_token + '&sender_hash=' + sender_hash,
                            beforeSend:function(){
                                console.log("O seu pedido está sendo processado. Aguarde...");
                            },
                            success: function(data) {
                                console.log("Obrigado por doar. O seu pedido foi processado com sucesso!");
                            },
                            error: function (data) {
                                console.log("Ocorreu um erro ao enviar os dados. Tente novamente.")
                            }

                        });


                    });


                });

The problem is that the controller does not receive the damn posts.

Set the following in the control if the $ _POST [submit_pay] is sent, it will get $ _POST ['cc_token'] and $ _POST ['sender_hash'] (already tried up submit )

It would take the posts sent by Ajax. It's what should happen, but it does not. I can not evict POST with the card token and sender_hash. What am I doing wrong?

    
asked by anonymous 11.10.2015 / 03:31

1 answer

1

Good afternoon. You're sending via Http, right? Instead of using $_POST[''] try using $this->post('');

I had this same problem when I implemented a RestFull with Codeigniter.

    
19.10.2015 / 19:11