Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 插入数据并更新引导数据表分页在刷新后不起作用_Jquery_Ajax_Twitter Bootstrap_Pagination_Datatables - Fatal编程技术网

Jquery 插入数据并更新引导数据表分页在刷新后不起作用

Jquery 插入数据并更新引导数据表分页在刷新后不起作用,jquery,ajax,twitter-bootstrap,pagination,datatables,Jquery,Ajax,Twitter Bootstrap,Pagination,Datatables,当有人添加类别时,我想刷新此页面。但当我使用ajax刷新div时,它会丢失分页,然后引导分页不起作用并显示所有数据……但在添加数据之前,它的分页工作正常 <table class="table table-bordered datatable dataTable" id="table_export" aria-describedby=""> <thead> <tr role="row"> <th width

当有人添加类别时,我想刷新此页面。但当我使用ajax刷新div时,它会丢失分页,然后引导分页不起作用并显示所有数据……但在添加数据之前,它的分页工作正常

<table class="table table-bordered datatable dataTable" id="table_export" aria-describedby="">
    <thead>
        <tr role="row">
            <th width="80" class="sorting_asc" role="columnheader" tabindex="0" aria-controls="table_export" rowspan="1" colspan="1" aria-sort="ascending" aria-label="roll: activate to sort column descending" style="width: 62px;"><div>SL</div></th>
            <th width="80" class="sorting" role="columnheader" tabindex="0" aria-controls="table_export" rowspan="1" colspan="1" aria-label="photo: activate to sort column ascending" style="width: 62px;"><div>Category Name</div></th>
            <th class="sorting" role="columnheader" tabindex="0" aria-controls="table_export" rowspan="1" colspan="1" aria-label="name: activate to sort column ascending" style="width: 255px;"><div>Status</div></th>
            <th class="span3 sorting" role="columnheader" tabindex="0" aria-controls="table_export" rowspan="1" colspan="1" aria-label="address: activate to sort column ascending" style="width: 235px;"><div>Action</div></th>
    </thead>

    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <?php
            $students = $this->db->get('brands')->result_array();
            $i = 0;
            foreach ($students as $row):
                ?>
                <tr class="odd">
                    <td class=" sorting_1"><?php echo $i += 1 ?></td>
                    <td class=" "><?php echo $row['name']; ?></td>
                    <td class=" ">
                        <?php if ($row['status'] == 0) {
                            echo "Un Publish";
                        } elseif ($row['status'] == 1) {
                            echo "Publish";
                        } ?>
                        </td>
                        <td class=" ">

                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                    Action <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-default pull-right" role="menu">

                                    <!-- STUDENT EDITING LINK -->
                                    <li>
                                        <a href="#" onclick="showAjaxModal('<?php echo base_url(); ?>modal/popup/modal_brands_edit/<?php echo $row['id']; ?>');">
                                            <i class="entypo-pencil"></i>
                                            edit
                                        </a>
                                    </li>
                                    <li class="divider"></li>

                                    <!-- STUDENT DELETION LINK -->
                                    <li>
                                        <a href="#" onclick="confirm_modal('<?php echo base_url(); ?>Admin/category/delete/<?php echo $row['id']; ?>');">
                                            <i class="entypo-trash"></i>
                                            delete
                                        </a>
                                    </li>
                                </ul>
                            </div>

                        </td>
                    </tr>
                    <?php endforeach; ?>
        </tbody>
    </table>
    <textarea disabled="disabled"></textarea>
    <!-----  DATA TABLE EXPORT CONFIGURATIONS ----->
    <script type="text/javascript">

        jQuery(document).ready(function ($) {


            var datatable = $("#table_export").dataTable({
                "sPaginationType": "bootstrap",
                "sDom": "<'row'<'col-xs-3 col-left'l><'col-xs-9 col-right'<'export-data'T>f>r>t<'row'<'col-xs-3 col-left'i><'col-xs-9 col-right'p>>",
                "oTableTools": {
                    "aButtons": [

                        {
                            "sExtends": "xls",
                            "mColumns": [0, 1, 2]
                        },
                        {
                            "sExtends": "pdf",
                            "mColumns": [0, 1, 2]
                        },
                        {
                            "sExtends": "print",
                            "fnSetText": "Press 'esc' to return",
                            "fnClick": function (nButton, oConfig) {
                                datatable.fnSetColumnVis(3, false);

                                this.fnPrint(true, oConfig);

                                window.print();

                                $(window).keyup(function (e) {
                                    if (e.which == 27) {
                                        datatable.fnSetColumnVis(1, true);
                                        datatable.fnSetColumnVis(5, true);
                                    }
                                });
                            },

                        },
                    ]
                },

            });

            $(".dataTables_wrapper select").select2({
                minimumResultsForSearch: -1
            });
        });

    </script>

SL
类别名称
地位
行动
行动
jQuery(文档).ready(函数($){ var datatable=$(“#table_export”).datatable({ “sPaginationType”:“引导程序”, “sDom”:“t”, “可旋转工具”:{ “阿布顿”:[ { “性倾向”:“xls”, “McColumns”:[0,1,2] }, { “性倾向”:“pdf”, “McColumns”:[0,1,2] }, { “性倾向”:“打印”, “fnSetText”:“按“esc”返回”, “fnClick”:功能(N按钮、oConfig){ datatable.fnSetColumnVis(3,false); 此.fnPrint(正确,oConfig); window.print(); $(窗口).keyup(函数(e){ 如果(e.which==27){ datatable.fnSetColumnVis(1,true); datatable.fnSetColumnVis(5,真); } }); }, }, ] }, }); $(“.dataTables\u包装选择”)。选择2({ 搜索的最小结果:-1 }); });
这是我的ajax.php

<script type="text/javascript">
    $(document).ready(function (e) {
        $("#addtag").on('submit', (function (e) {
            e.preventDefault();
            $.ajax({
                url: "<?php echo base_url(); ?>Admin/brands/create",
                type: "POST",
                data: new FormData(this),
                contentType: false,
                cache: false,
                processData: false,
                success: function (data) {
                    $("input[name=name]").val(data);
                    $("div.status select").val("1");
                    $('#table_export').load(document.URL + ' #table_export');


                    var mytable =

                    $('#table_export').DataTable({
                        "paging": true,
                        "lengthChange": false,
                        "searching": false,
                        "ordering": true,
                        "info": true,
                        "autoWidth": false,
                        "sDom": 'lfrtip'
                    });
                    mytable.reload();
                },
                done: function (data) {
                },
                error: function () {
                }
            });
        }
        ));
    });
</script>

$(文档).ready(函数(e){
$(“#addtag”)。在('提交',(函数(e){
e、 预防默认值();
$.ajax({
url:“管理员/品牌/创建”,
类型:“POST”,
数据:新表单数据(本),
contentType:false,
cache:false,
processData:false,
成功:功能(数据){
$(“输入[名称=名称]”).val(数据);
$(“div.status select”).val(“1”);
$('#table_export')。加载(document.URL+'#table_export');
var mytable=
$('table#u export')。数据表({
“分页”:正确,
“长度变化”:错误,
“搜索”:错误,
“排序”:正确,
“信息”:正确,
“自动宽度”:false,
“sDom”:“lfrtip”
});
mytable.reload();
},
完成:功能(数据){
},
错误:函数(){
}
});
}
));
});
在插入值之前,显示分页

在这里添加类别

插入值后分页不起作用并显示每个值。

无页面刷新的总工作量插入数据并同时更新数据表…

使用Ajax

<script type="text/javascript">
                                $(document).ready(function (e) {
                                    $("#addtag").on('submit', (function (e) {
                                        e.preventDefault();
                                        $.ajax({
                                            url: "<?php echo base_url(); ?>Admin/brands/create",
                                            type: "POST",
                                            data: new FormData(this),
                                            contentType: false,
                                            cache: false,
                                            processData: false,
                                            success: function (data)
                                            {

                                                $("input[name=name]").val(data);
                                                $("div.status select").val("1");
                                                $('#table_export').bootstrapTable("load");
                                                $('#table_export').load(document.URL + ' #table_export');


                                                table.bootstrapTable('refresh');
                                            },
                                            done: function (data) {
                                            },
                                            error: function ()
                                            {
                                            }
                                        });
                                    }
                                    ));
                                });
                            </script>

$(文档).ready(函数(e){
$(“#addtag”)。在('提交',(函数(e){
e、 预防默认值();
$.ajax({
url:“管理员/品牌/创建”,
类型:“POST”,
数据:新表单数据(本),
contentType:false,
cache:false,
processData:false,
成功:功能(数据)
{
$(“输入[名称=名称]”).val(数据);
$(“div.status select”).val(“1”);
$(“#表_导出”).bootstrapTable(“加载”);
$('#table_export')。加载(document.URL+'#table_export');
表.bootstrapTable('refresh');
},
完成:功能(数据){
},
错误:函数()
{
}
});
}