按顺序提交所有页面的dataTable中的所有数据

时间:2019-06-27 06:05:11

标签: jquery ajax datatable

在这里,我想将所有页面的dataTable中包含的所有数据提交到数据库,因为我已经这样写了代码

 $('.sales_purchase_button').on('click', function(e){

  e.preventDefault();

    var sData = table.$('input').serialize();
    var theForm = $(this).closest('form');

        $.ajax({
            type: "POST",
            url: "<?php echo base_url();?>admin_control/add_sales_purchase",                
            data: sData,
            success: function(data){
                console.log($('#sales_purchase').serialize());

            }
        });
        e.preventDefault(); 

    }); 

数据正在插入,但是问题是,当我从任何显示页面单击提交按钮时,值是从病房插入的,而不是从首页插入的值。我想从病房的第一页插入。

我的html页面看起来像这样

<form id="sales_purchase"  method="POST">
          <table id="myTableinvoice" class="table table-bordered table_repo">
                      <thead class="thead-light">
                      <tr>
                      <th>Client</th>
                      <?php foreach($months as $month){?>
                        <th><?php echo $month->format("M-Y");?>(Sales)</th>

                       <?php } ?>
                       <!--<th>Total sale</th>-->
                       <?php foreach($months as $month){?>
                        <th><?php echo $month->format("M-Y");?>(Purchase)</th>

                       <?php } ?>
                       <?php foreach($months as $month){?>
                       <th><?php echo $month->format("M-Y");?>(Expenses)</th>
                       <?php } ?>
                      </tr>
                </thead>
                <tfoot>
                     <tr>
                    <th>Client</th>
                    <?php foreach($months as $month){?>

                        <th><?php echo $month->format("M-Y");?>(Sales)</th>

                       <?php } ?>
                       <!--<th>Total sale</th>-->

                       <?php foreach($months as $month){?>
                        <th><?php echo $month->format("M-Y");?>(Purchase)</th>

                       <?php } ?>
                       <?php foreach($months as $month){?>
                       <th><?php echo $month->format("M-Y");?>(Expenses)</th>
                       <?php } ?>
                    </tr>
                </tfoot>
                <tbody>
                   <?php $net_total=0;$br=0;$i=0; if(!empty($client_details)){
                       foreach ($client_details as $key => $client_detail) {

                         ?>
                        <tr class="tr" >
                        <td data-filter="<?= $client_detail->client_name;?>" nowrap><?php if($client_detail->client_name) echo $client_detail->client_name; else echo "NULL";?></td>
                        <input type="hidden" id="hidden_client_id" name="hidden_client_id[]" value="<?= $client_detail->id;?>">
                        <input type="hidden" id="client_id" name="client_id<?php echo $i;?>[]" value="<?= $client_detail->id;?>">

                        <?php foreach($months as $month){?>

                        <input type="hidden" class="" name="months<?php echo $i;?>[]" value="<?php echo $month->format("M");?>" >
                        <input type="hidden" class="" name="year<?php echo $i;?>[]" value="<?php echo $month->format("Y");?>" >
                        <td><input type="text" class="sales_amount" name="sales_amount<?php echo $i;?>[]" ></td>

                        <?php } ?>
                        <!--<td><input type="text" readonly="readonly" class="total_sale" name="total_sale<?php echo $i;?>" ></td>-->
                       <?php foreach($months as $month){
                           ?>

                        <td><input type="text" class="sales_amount" name="purchase_amount<?php echo $i;?>[]"></td>

                       <?php } ?>
                       <?php foreach($months as $month){?>
                       <td><input type="text" name="expense_amount<?php echo $i;?>[]"></td>
                       <?php } ?>




            </tr>

                    <?php $i++;  }
                   } ?>









                </tbody>

            </table>
            <div class="form-group" style="margin-top: 20px">

            <input type="hidden" name="group" id="group" value="<?php echo $group;?>">
            <input type="button" id="sales_purchase_button" class="btn btn-primary sales_purchase_button" style="font-weight: bold" value="Create" />
            <p><button>Submit</button></p>

        </div>
        </form>

2 个答案:

答案 0 :(得分:0)

序列化整个表格

def load_checkpoint(filepath):
    print(filepath)
    **checkpoint = torch.load(filepath)**
    print(checkpoint.keys())
    if checkpoint['arch'] == p_ague.arch:
        model = models.vgg19(pretrained= True)
    if checkpoint['arch'] == p_ague.arch:
        model = models.alexnet(pretrained= True)
    for param in model.parameters():
        param.requires_grad = False
    else:
        print('Model Not recognised')

    model.class_to_idx = checkpoint['class_to_idx']

    model.classifier = nn.Sequential(nn.Linear(p_ague.input_units, p_ague.hidden_units),
                                 nn.Dropout(p_ague.dropout),
                                 nn.ReLU(),
                                 nn.Linear(p_ague.hidden_units,  p_ague.output_units),
                                 nn.LogSoftmax(dim=1))
    model.load_state_dict(checkpoint['state_dict'])
    return model

**model = load_checkpoint(p_ague.checkpoint)**

答案 1 :(得分:0)

我为您创建了一个JSFiddle。以下是javascript中的相关部分:

{{1}}

完成JSFiddle here

是斯巴达人的例子,但我尝试模拟您的环境。运行并查看控制台日志。我可以捕获表所有行的所有输入形式。