Php Codeigniter和AJAX从表中删除项将页面留空

Php Codeigniter和AJAX从表中删除项将页面留空,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我设法将ajax集成到分页和搜索中。到目前为止似乎效果不错。但是,当我删除一个项目并尝试刷新列表时,我的页面将返回空白。我希望有人能指导我正确的方法来做这件事,因为我已经尝试了各种方法,并且想尝试使用ajax。多谢各位 我的看法 <script> function searchFilter(page_num) { page_num = page_num?page_num:0; var keywords = $('#search').val(); con

我设法将ajax集成到分页和搜索中。到目前为止似乎效果不错。但是,当我删除一个项目并尝试刷新列表时,我的页面将返回空白。我希望有人能指导我正确的方法来做这件事,因为我已经尝试了各种方法,并且想尝试使用ajax。多谢各位

我的看法

<script>
function searchFilter(page_num) {
    page_num = page_num?page_num:0;
    var keywords = $('#search').val();
        console.log(keywords);
        console.log('<?php echo site_url('/AdminDocuments/'); ?>'+page_num);
    $.ajax({
        type: 'POST',
        url: '<?php echo site_url('/AdminDocuments/Search/'); ?>'+page_num,
        data:'page='+page_num+'&keywords='+keywords,
        beforeSend: function () {
            $('.loading').show();
        },
        success: function (html) {
            $('#list').html(html);
            $('.loading').fadeOut("slow");
        }
    });
}

function deleteDocument(input){
    var id = input;
    console.log(id);
    $.ajax({
        type:'POST',
        url:'<?php echo site_url('/AdminDocuments/Delete'); ?>',
        data:'id='+id,
        beforeSend: function () {
            $('.loading').show();
        },
        success:function(result){
            console.log(result);
            $('#list').html(result);
            $('.loading').fadeOut("slow");
        }
    });
}
</script>
<div id="successid" style="display: none;" class="alert alert-success">
    <button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true">
        &times;
    </button>
    Success 
</div>
<div id="maincontainer">
    <div id="list" class="row">
        <div class="col-sm-12 table-responsive">
            <table class="table">
                <thead>
                    <tr class="text-left">
                        <td>Period</td>
                        <td>Name</td>
                        <td>Account Number</td>
                        <td></td>
                        <td></td>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                        if(!empty($datatable)){
                            foreach ($datatable as $data){
                    ?>
                        <tr class="text-left">
                            <td><?php echo $data['month']."/"; ?><?php echo $data['year']; ?></td>
                            <td><?php echo $data['first_name']; ?> <?php echo $data['last_name']; ?></td>
                            <td><?php echo $data['account_number']; ?></td>
                            <td><a href="<?php echo $data['file_link'];?>"><i class="fa fa-file" aria-hidden="true"></i> View</a></td>
                            <!--<td><a href="<?php echo site_url('AdminDocuments/Delete/'.$data['document_id']);?>"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a></td>-->
                            <td><a href="#" id="delete" onclick="deleteDocument(<?php echo $data['document_id'];?>)"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a></td>
                        </tr>
                    <?php 
                        }
                    }else{
                    ?>
                        <tr>
                            <td colspan="7">You do not have any items at the moment</td>
                        </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div class="pagination-links pull-right">
            <?php echo $links; ?>
        </div>
    </div>
    <div class="loading" style="display: none;">
        <div class="content">
            <img src="<?php echo base_url().'assets/images/loading/loading.gif'; ?>"/>
        </div>
    </div>
</div>

这一行在deleteDocument函数$'list'.htmlresult的成功中;正在导致列表div替换为true或false
你想要的是在成功后再次调用分页脚本

我认为你犯了一个错误。请评论此行/$'list'.htmlresult;,因为这将用结果数据替换列表div

function deleteDocument(input){
    var id = input;
    console.log(id);
    $.ajax({
        type:'POST',
        url:'<?php echo site_url('/AdminDocuments/Delete'); ?>',
        data:'id='+id,
        beforeSend: function () {
            $('.loading').show();
        },
        success:function(result){
            console.log(result);
            // $('#list').html(result);
            $('.loading').fadeOut("slow");
        }
    });
}

如果它不适合您,请告诉我。

它返回的是真还是假?当你删除时?我认为你需要正确地转义单引号,所以在单引号url内使用双引号:,您好,非常感谢您的回答!我该怎么做呢?我试过在成功后放置$this->索引,但我觉得应该有更好的方法,因为它不允许我发送消息。嗨!谢谢你的帮助!但这将如何刷新我的列表?因此,在再次注释代码后,您必须使用page_num参数调用searchFilterpage_num函数。这意味着我必须将page num设置为此函数中的输入,并将其传递给searchFilter?
function deleteDocument(input){
    var id = input;
    console.log(id);
    $.ajax({
        type:'POST',
        url:'<?php echo site_url('/AdminDocuments/Delete'); ?>',
        data:'id='+id,
        beforeSend: function () {
            $('.loading').show();
        },
        success:function(result){
            console.log(result);
            // $('#list').html(result);
            $('.loading').fadeOut("slow");
        }
    });
}