Ajax帖子和代码点火器

I need to send 2 values to my codeigniter controller complete the request. But I failed in all attempts.

My Controller need to receive:

$token = $this->input->post('cc_token');
$hash = $this->input->post('sender_hash');

Ajax

$(document).ready(function ({
    var sender_hash = myfunction.getSenderHash();

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

        },
        error: function (response) {
            console.log(response);
        }
    });
    $("#submit").click(function () {

        $.ajax({
            url: '<?php echo $details->id?>',
            type: 'POST',
            data: 'cc_token=' + card_token + '&sender_hash=' + sender_hash,
            beforeSend: function () {
                console.log("Your request is being processed. Wait...");
            },
            success: function (data) {
                console.log("Thank you for donating. Your request has been successfully processed!");
            },
            error: function (data) {
                console.log("There was an error sending the data. Try again.")
            }

        });
    });
});

But the post was not send to controller. What i'm doing wrong? If i put these values in input, works fine, but I don't wanna to do that, because this is not the right way.

Try the below with base_url()

Make sure you have setup the base_url in config.php

Goto: application->config->config.php

Also auto load the url helper

Goto: application->config->autoload.php

And try the below code,

$(document).ready(function ({
    var sender_hash = myfunction.getSenderHash();

        var hash = '';

    var card_token = myFunction.createCardToken({
        cardNumber: "4111111111111111",
        brand: 'visa',
        cvv: "123",
        expirationMonth: "12",
        expirationYear: "2030",
        success: function (response) {
                    hash = response;
        },
        error: function (response) {
            console.log(response);
        }
    });
    $("#submit").click(function () {
        $.ajax({
            url: '<?php echo base_url();?>index.php/donate/pay/<?php echo $details->id?>',
            type: 'POST',
            data: {'cc_token':hash,'sender_hash':sender_hash},
            beforeSend: function () {
                console.log("Your request is being processed. Wait...");
            },
            success: function (data) {
                console.log("Thank you for donating. Your request has been successfully processed!");
            },
            error: function (data) {
                console.log("There was an error sending the data. Try again.")
            }

        });
    });
});