如何在控制器和模型(代码点火器)中访问jQuery变量以便将数据发送到数据库?

时间:2016-10-04 11:40:56

标签: javascript jquery codeigniter

如何在控制器和模型(代码点火器)中访问jQuery变量以便将数据发送到数据库?

脚本:

<script>
    var firstSeatLabel = 1;
    $(document).ready
    (
        function() 
     {
     var $cart = $('#selected-seats'),
     $counter = $('#counter'),
     $total = $('#total'),
     sc = $('#seat-map').seatCharts({
     map: [

控制器:

public function checkout()
{
    $selected_seats=$this->input->post('selected_seats');   
    $total=$this->input->post('total');
    $table='seat_details';
    $data=array('selected_seats'=> $selected_seats,'total_amount'=>$total);

查看:

<h3> Selected Seats (
        <span id="counter"> 0</span>
        ):
    </h3>
     <ul id="selected-seats"></ul>Total: 
     <b>$ <span id="total">0</span> </b>
    <form action="<?php echo site_url('Welcome/checkout');?>" method="POST">
                <button class="checkout-button" type="submit">
                      Checkout
                 </button>

1 个答案:

答案 0 :(得分:0)

使用jquery设置输入值并使用PHP获取脚本中的值:

$('#input-checkout').attr('value',20);

你的页面有一个隐藏的字段,如下所示:

<input type="hidden" name="checkout" id="input-checkout">

在您的CI控制器中,您只需获取Checkout值,如下所示:

$checkout= $this->input->post('checkout');