【问题标题】:how to clear datatable before ajax load from another ajax如何在从另一个 ajax 加载 ajax 之前清除数据表
【发布时间】:2023-03-03 17:50:02
【问题描述】:

需要帮助我有 3 个 ajax 在哪里 - 如果单击将显示 ajax B,则来自 ajax A 的数据有按钮 - 如果单击将显示 ajax C,则来自 ajax B 的数据有按钮 问题是当我寻找新的搜索时,来自 ajax A 的数据表 来自 ajax B 的数据仍然是旧的 如何在加载 ajax A 之前清除来自 ajax B 和 C 的数据 这是我的 ajax A 代码:

<script type="text/javascript">
var save_method; //for save method string
var table; //for ajax A
var table2; // for ajax B
var table3;  // for ajax C
var base_url = '<?php echo base_url()?>';
   // table2 = $('#table_id2').clear();
  //  table2 = $('#table_id2').rows.add(response.data);
  //  table2 = $('#table_id2').draw();
    $(document).ready(function() {
    //datatables
    table = $('#table_id').DataTable({         
        "lengthMenu": [[5, 10, 25, -1], [5, 10, 25, "All"]],
        "deferLoading": 0,
        "processing": true, //Feature control the processing indicator.
        "language": {
            "processing": "<span><img src='images/Preloader_3.gif'/></span>"
            }, // you can put text or html here in the language.processing setting.            
        "serverSide": true, //Feature control DataTables' server-side processing mode.
        "order": [], //Initial no order.
        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo base_url('infoemployee/ajax_list')?>",            
            "type": "POST",
        },      
        //Set column definition initialisation properties.
        "columnDefs": [
            {
                "targets": [ -1 ], //last column
                "orderable": false, //set not orderable
            },                  
        ],
    }); });

【问题讨论】:

    标签: javascript json ajax codeigniter


    【解决方案1】:

    在这个块之后

        "ajax": {
            "url": "<?php echo base_url('infoemployee/ajax_list')?>",            
            "type": "POST",
        }, 
    

    在上面添加这一行

    "destroy" : true,
    

    【讨论】:

    • 嗨,伊万,“破坏”是什么意思:是的,ajax A 还是 ajax B?
    • 两者都有,一定要试一试才能理解
    • 感谢 ivan 将代码添加到我所有的 ajax 中
    • 嗨,ivan,我可以再次问你如何在我使用搜索之前将我的数据表显示为空,我尝试使用“延迟加载”:0,但在我搜索新数据后,数据表返回以显示所有数据。 . 谢谢之前
    • @WahyuArtadianto 搜索时是使用按钮还是其他方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 2015-05-17
    • 2018-02-10
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多