【问题标题】:DataTable pagination not working with codeigniterDataTable分页不适用于codeigniter
【发布时间】:2020-03-12 10:33:01
【问题描述】:

使用数据表显示记录时我没有问题。问题是当我单击下一个/上一个按钮时,它将路由到 404 Page Not Found。 我的js代码:

$.ajax({
        url     : "position/load_position",
        method  : "POST",
        dataType: "json",
        success : function (data) {
            $('#position_list').html(data);
            $('#position_data').dataTable( );
        }, 
    });

我的php代码:

public function load_position()
{
    $position  = $this->position_model->fetch_position();
    $output = '';

    $output .= '
        <div class="table-responsive table-responsive-data2">
            <table id="position_data" class="table " cellspacing="0" width="100%">
                <thead class="  ">
                    <tr>
                        <th>ID</th> 
                        <th>position</th>
                        <th>Edit</th>
                        <th>Delete</th>
                    </tr>
                </thead>
                <tbody>
    ';

    if ($position->num_rows() > 0) {
        foreach ($position->result_array() as $row) {
            $output .= '
                    <tr>
                        <td>' . $row['position_id'] . '</td> 
                        <td>' . ucfirst($row['position']) . '</td>
                        <td><a title="Edit" href="#" class=" text-warning h5"><i class="fa fa-edit"></i></a></td>
                        <td><a href="#" title="Delete" class="text-danger h5 delete_position"><i class="fa fa-trash"></i></a></td>
                    </tr> 
            ';
        }
    } 

    $output .= '
                </tbody>
            </table>
        </div>
    ';

    echo json_encode($output);
}

Clicking the pagination

route to 404 Page not found

【问题讨论】:

  • 因为它在URL中传递undefined,解决这个问题,如果没有更多错误它可能会工作。

标签: php codeigniter datatable datatables


【解决方案1】:

检查 ajax 网址

 $.ajax({
        type : "POST",
        url  : "<?php echo site_url(); ?>/controllerName/FunctionName"
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多