PHP Datatables 请求未知参数错误

PHP Datatables Requested unknown parameter error

提问人:phpcalismak 提问时间:7/26/2023 最后编辑:phpcalismak 更新时间:7/29/2023 访问量:44

问:

我正在尝试使用AJAX和日期范围过滤将jQuery DataTables与服务器端PHP一起使用

JavaScript 代码


$(document).ready(function() {
    $('#start_date, #end_date').datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true
    });

    var dataTable = $('#data-table').DataTable({
        ajax: {
            url: 'server_processing.php',
            data: function (d) {
                d.start_date = $('#start_date').val();
                d.end_date = $('#end_date').val();
            }
        },
        processing: true,
        serverSide: true,
        columns: [
            { "data": 'idbir' },
            { "data": 'Tarih' },
            { "data": 'Name' },
            { "data": 'Accred' }
        ]
    });

   
    $('#start_date, #end_date').on('change', function() {
        dataTable.ajax.reload();
    });
});


  

server_processing.php

<?php
$sql_details = array(
    'user' => 'root',
    'pass' => '',
    'db'   => 'countries',
    'host' => 'localhost'
);
$table = 'collegescores';
$primaryKey = 'idbir';

$columns = array(
    array('db' => 'idbir', 'dt' => 0),
    array(
        'db'        => 'Tarih',
        'dt'        => 1,
        'formatter' => function ($d,$row) {
            return date('Y-m-d', strtotime($d));
        }
    ),
    array('db' => 'Name', 'dt' => 2),
    array('db' => 'Accred', 'dt' => 3)
);



require('ssp.class.php');
$where = '';
if (isset($_GET['start_date'])) {
    $start_date = date('Y-m-d', strtotime($_GET['start_date']));
    $where .= "Tarih >= '$start_date'";
}

if (isset($_GET['end_date'])) {
    $end_date = date('Y-m-d', strtotime($_GET['end_date']));
    $where .= ($where ? ' AND ' : '') . "Tarih <= '$end_date'";
}

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

错误:DataTables 警告:table id=data-table - 请求了第 0 行第 0 列的未知参数“idbir”。有关此错误的详细信息,请参阅 http://datatables.net/tn/4

php jquery mysql ajax 数据表

评论

0赞 Liam Morton 7/26/2023
您的 PHP 文件名是 quistion 中的文件名还是 ajax 脚本中的文件名?server-processing.phpserver_processing.phpurl
0赞 phpcalismak 7/26/2023
@LiamMorton对不起,错别字,因为它在我的 ajax 脚本中
0赞 Liam Morton 7/26/2023
好的,错别字发生了,所以要确保。如果它不是错别字,那么它将与你在ajax中的值有关。因为看起来你没有适当的价值。从外观上看,您将发送到此值的值将不起作用。那么,当您运行 AJAX 脚本时,您希望接收什么值?datefunction (d)server_processing.phpserver_processing.php
0赞 phpcalismak 7/26/2023
@LiamMorton我从输入中接收start_date和end_date。我没有发布完整的html代码,因为我认为它会非常拥挤。我不明白你的回答。您能否展示如何解决该接收错误。谢谢。
0赞 CBroe 7/26/2023
从错误消息向您介绍的解释来看,您似乎正在处理此处的“参数是字符串”情况。“这将表明使用 columns.data 的列无法获取要显示的有效数据”——那么你的 PHP 返回的 JSON 到底是什么样子的?

答: 暂无答案