JQuery未捕获类型错误:无法读取属性';重新加载';未定义的

JQuery未捕获类型错误:无法读取属性';重新加载';未定义的,jquery,datatable,Jquery,Datatable,我想在数据库中插入新数据后重新加载datatable。我已经写了这段HTML代码 <table class="table table-striped table-bordered bootstrap-datatable datatable" id="Slider_table"> <thead> <tr> <th>Title</th> <th>Price</th> &

我想在数据库中插入新数据后重新加载datatable。我已经写了这段HTML代码

<table class="table table-striped table-bordered bootstrap-datatable datatable" id="Slider_table">
<thead>
    <tr>
        <th>Title</th>
        <th>Price</th>
    </tr>
</thead>
<tbody>
    <?php foreach($items as $row){?>
    <tr>
        <td><?=$row->item_title;?></td>
        <td class="center"><?=$row->item_price;?></td>
   </tr>
</tbody>
你可以用

  dtable.draw();

成功之后。它将刷新数据表

您必须将数据表引用存储在一个变量中。根据您使用的代码,您不能使用DataTableAjax重载方法

因此,您必须应用以下解决方案:

定义表变量: var表

并在documentready函数上像这样加载datatable

table = $("#Slider_table").DataTable();

$('#add_items').on('click', function(e){
    e.preventDefault();
    var formData = new FormData($("#form1")[0]); //It automatically collects all fields from form

    $.ajax({
        url: "<?= base_url(); ?>Items/add_items",
        type: "post",
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function(output) {
            table.row.add($(output)).draw();
            // Here in output you have to return table rows html from php

        }
    });
});
table=$(“#Slider_table”).DataTable();
$('add#u items')。在('click',函数(e)上{
e、 预防默认值();
var formData=new formData($(“#form1”)[0]);//它自动从表单收集所有字段
$.ajax({
url:“项目/添加项目”,
类型:“post”,
数据:formData,
async:false,
cache:false,
contentType:false,
processData:false,
成功:功能(输出){
table.row.add($(输出)).draw();
//在输出中,您必须从php返回表行html
}
});
});

reload在1.10.0版中可用,您使用的是哪个版本?参考undefined的'reload'表示它不可用。
.ajax至少有问题。@Deepak我使用的是最新版本$(“#Slider_table”).location.reload();或简单位置。重新加载();成功之后?
table = $("#Slider_table").DataTable();

$('#add_items').on('click', function(e){
    e.preventDefault();
    var formData = new FormData($("#form1")[0]); //It automatically collects all fields from form

    $.ajax({
        url: "<?= base_url(); ?>Items/add_items",
        type: "post",
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function(output) {
            table.row.add($(output)).draw();
            // Here in output you have to return table rows html from php

        }
    });
});