Send POST with Ajax and Codeigniter

Asked

Viewed 366 times

2

For almost 1 day I am facing a problem that so far can only solve (make sure I was right) doing the wrong, IE, gambiarras.

I’m trying to create the Transparent Checkout of Pagseguro but I can’t send the POST with the Credit Card token and the "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 doesn’t get the damn posts.

Set in control the following, if the $_POST["pagar_card"] (Submit) is sent, it will receive the $_POST['cc_token'] and $_POST['sender_hash'] (I’ve tried even outside of Submit)

He would take the posts sent by Ajax. That’s what should happen, but it doesn’t. I can’t see the POST with the card and sender_hash token. What I’m doing wrong?

  • Good afternoon. You’re sending via HTTP, right? Instead of using $_POST[''] try to use the $this->post(''); I had the same problem when I implemented a Restfull with Codeigniter.

No answers

Browser other questions tagged

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