如何在Codeigniter的数据表中发送Ajax请求 [英] How to send ajax request in Datatables in Codeigniter

查看:73
本文介绍了如何在Codeigniter的数据表中发送Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用此 ignited_datatables https:/ /github.com/IgnitedDatatables/Ignited-Datatables 在我的 CodeIgniter项目中。它从数据库成功返回数据。但是主要的问题是,当我添加新记录时,新插入的数据未显示在表<$中c $ c>自动,当我刷新页面时,新插入的数据为然后显示在中。因此我想通过 ajax 自动显示该数据,而不必<刷新页面。

I Have used this ignited_datatables https://github.com/IgnitedDatatables/Ignited-Datatables in my CodeIgniter project. It successfully returns data from the database. But the main problem is that when I add a new record the newly inserted data is not shown in the table automatically and when I refresh the page then the newly inserted data is then shown in the table. so I want to show that data automatically through ajax and I have not to refresh the page.

我的视图

<div class="box-body table-responsive">
    <table id="Slider_table" class="table table-bordered table-hover">
       <thead>
         <tr>
           <th>ID</th>
           <th>Title</th>
           <th>item_Price</th>
           <th>Description</th>
           <th>Status</th>
           <th>Action</th>
         </tr>
       </thead>
       <tbody>
       </tbody>
    </table>
</div><!-- /.box-body -->

此脚本在视图内

$(document).ready(function() {
    $("#Slider_table").dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxDataProp": "data",
        "fnServerData": function(sSource, aoData, fnCallback){
            $.ajax({
                "dataType": "json",
                "type"    : "POST",
                "url"     : "'.base_url().'Home/items_list/list",
                "data"    : aoData,
                "success" : function(res){

                 fnCallback(res);
                }
            });
        }
    });
  });


推荐答案

我认为您需要使用 draw( )方法,以便更新表的显示。

I think you need to use draw() method after success in order to have the table's display updated.

    table.row.add( {
            //you dynamic data
            "name":       "Tiger Nixon",
            "position":   "System Architect",
            "salary":     "$3,120",
            "start_date": "2011/04/25",
            "office":     "Edinburgh",
            "extn":       "5421"
        } ).draw(); 

根据文档。请参考 draw()

这篇关于如何在Codeigniter的数据表中发送Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆