错误:DataTables警告:table id = example - 使用DataTables服务器端AJAX请求的未知参数

时间:2018-04-06 07:37:17

标签: php json datatables

简介 我正在做一个服务器端的datatables.net json插件。

错误 一旦我尝试添加我的最后一列和第6列<th>Action,,我收到此错误消息:

  

“DataTables warning:table id = example - 请求的未知参数   第0行第6列为“6”。有关此错误的详细信息,请参阅   见http://datatables.net/tn/4

之前我收到过此错误消息,并知道它通常意味着什么。但为什么它试图从数据库中提取数据呢?我从未使用$subdata[]=$row[6];我甚至在这里观看过视频:https://www.youtube.com/watch?v=tCB2BHCVSjs。此外,当您在错误消息上单击“确定”时,表将加载为完全正常(除了没有按钮)。 Index.php:

    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>ID</th>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Position</th>
                    <th>Date</th>
                    <th>Updated</th>
<th>Action</th>
                </tr>
            </thead>
    </table>

<?php
$records = mysqli_query($con, "SELECT * FROM employees");
$totalData= $records->num_rows;
$totalFiltered=$totalData;
$data=array();
while ($row = mysqli_fetch_array($records)) { 
    $subdata=array();
    $subdata[]=$row[0]; //id
    $subdata[]=$row[1]; 
    $subdata[]=$row[2]; 
    $subdata[]=$row[3]; 
    $subdata[]=$row[4]; 
    $subdata[]=$row[5]; 
      $subdata[]='<button></button>'; 
    $data[]=$subdata;
}

$requestData= $_REQUEST;

Server.php

 $json_data = array(
                      "draw" => intval(isset($_GET['draw'])), 
                      "recordsTotal"    => intval( $totalData ), 
                      "recordsFiltered" => intval( $totalFiltered ),
                      "data"            => $data //How To Retrieve This Data
                     );

    echo json_encode($json_data);  
    ?>

$table = 'employees';

// Table's primary key
$primaryKey = 'id';

$columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'first_name', 'dt' => 1 ),
    array( 'db' => 'last_name',  'dt' => 2 ),
    array( 'db' => 'position',   'dt' => 3 ),
    array( 'db' => 'date',     'dt' => 4 ),
     array( 'db' => 'updated',     'dt' => 5 ),

);

// SQL server connection information
$sql_details = array(
    'user' => 'id3741634_username',
    'pass' => 'password',
    'db'   => 'id3741634_database',
    'host' => 'localhost'
);

require( 'ssp.class.php' );

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

1 个答案:

答案 0 :(得分:0)

试试这个

$data=array();
while ($row = mysqli_fetch_array($records)) { 
    $subdata['id']=$row['id']; //id
    $subdata['first']=$row['first']; //first
    $subdata['last']=$row['last']; //last
    $subdata['position']=$row['position']; //position
    $subdata['date']=$row['date']; //date
    $subdata['updated']=$row['updated']; //updated
    $subdata['button']='<button type="button" class="btn btn-warning">Warning</button>'; 
    $data[]=$subdata;
}

$requestData= $_REQUEST;
$json_data = array(
                  "draw" => intval(isset($_GET['draw'])), 
                  "recordsTotal"    => intval( $totalData ), 
                  "recordsFiltered" => intval( $totalFiltered ),
                  "data"            => $data //How To Retrieve This Data
                 );

json_encode($json_data);  
?>