重新加载后Jquery Datatable函数无法正常工作

时间:2016-04-27 06:53:37

标签: jquery datatables

我正在使用 Jquery Datatable 作为我的插件。 以下是代码示例:

$(function() {
    $( "#tab-per" ).DataTable();
});

$(function() {
    var form = document.getElementById("postme");
    $('form#postme').on('submit', function(e) {
            $.post('cnp.php?hal=103.sv', $(this).serialize(), function (data) {
            alert('Data perusahaan sukses disimpan !');
            $( "#tab-per" ).load( "cnp.php?hal=103 #tab-per" );
            $( "#tab-per" ).DataTable();
            form.reset();
            // This is executed when the call to mail.php was succesful.
            // 'data' contains the response from the request
            }).error(function() {
            alert('Mohon maaf ada kesalahan')
            // This is executed when the call to mail.php failed.
           });
          e.preventDefault();                   
    });
});

问题是,当表格刷新后单击提交按钮将数据保存到我的数据库时,数据表分页和搜索不再起作用。

1 个答案:

答案 0 :(得分:0)

你可以这样做:

 var tab-per-table;
 $(function() {
    tab-per-table=$(function() {
        $( "#tab-per" ).DataTable();
    });
 });
//when you post success,you can delete.$( "#tab-per" ).DataTable(),just do:
 tab-per-table.draw();
相关问题