weixin_33709219 2015-10-11 00:22 采纳率: 0%
浏览 25

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.

  • 写回答

1条回答 默认 最新

  • Memor.の 2015-10-11 01:41
    关注

    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.")
                }
    
            });
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上