如何通过ajax将选中的行数据传递到另一个数据表中?

时间:2015-12-23 10:10:55

标签: php jquery ajax wordpress

我正在尝试获取已检查的行数据,但我不知道如何从提交函数传递它。所以我可以将数据传递给另一个php datatable以及如何在我传递数据后检索数据?

$('#submit_form').on('submit', function(){
    //function to get the checkbox that is checked data and pass it to another php
});

我的html表

<form id="submit_form" action="<?php echo site_url('Test_product/import');?>">
<p align="right"><button name="import" type="submit" form="submit_form">Import </button></p>
<table id="import" width="100%">
    <thead>
        <tr>
          <th><input name="select" id="select" type="checkbox" checked></th>
            <th></th>
            <th>Name</th>
            <th>SKU</th>
       </tr>
   </thead>
        <tfoot>
        <tr>
            <th></th>
            <th></th>
            <th>Name</th>
            <th>SKU</th>
            </tr>
            </tfoot>
            </table>
            </form>

我的ajax

<script>

$(document).ready(function() {

        var table = $('#import').DataTable({

        bProcessing: true,
        ajax: "localhost/product.php",
        columns: [
            {
                data: 'id',
                searchable: false,
                orderable: false,
                className: 'dt-body-center',
                render: function (data, type, full, meta){
                return '<input type="checkbox" name="' +data+ '"'+ 'checked>'; }
            },
            {data: 'photo'},
            {data: 'name'},
            {data: 'sku'}
            ]
        });

        $('#select').on('click', function(){
          // Get all rows with search applied
          var rows = table.rows({ 'search': 'applied' }).nodes();
          // Check/uncheck checkboxes for all rows in the table
          $('input[type="checkbox"]', rows).prop('checked', this.checked);
        });
        $('#submit_form').on('submit', function(){
            var data = table.rows(this).data();
            alert(data[0]);
        });

});
</script>

我的json输出

{"data":[{"id":35,"name":"_testing_product_009","sku":"-","photo":""}]}

0 个答案:

没有答案