【问题标题】:how to retrive extra HTTP variables using datatables如何使用数据表检索额外的 HTTP 变量
【发布时间】:2012-07-07 09:58:15
【问题描述】:

我正在为 jquery 使用数据表插件,并且正在使用 fnServerParams 函数。我已经发送了一些额外的变量,但我不确定如何在 server_processing 文件中检索它们。

代码:

$('#fleetsTable').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/server_processing.php",
    "fnServerParams": function ( aoData ) {
        aoData.push( { "name": "customerId", "value": "6" } );
    }
} );

这是我在 server_processing.php 文件中尝试过的

$customerId = "";
if ( isset( $_GET['customerId'] ) )
{
    $customerId = $_GET['customerId'] ;
}

这似乎不起作用..

谢谢你的帮助

【问题讨论】:

  • 但是您将变量命名为“名称”。你收到的是$_GET['name'] = "customerID"; $_GET['value'] = "6";
  • 我会做一个 print_r($_GET);看看你真正得到了什么,如果有的话。

标签: php jquery datatables


【解决方案1】:

安德烈的评论是错误的。 Datatables 要求您以以下格式发送参数

aoData.push( { "name": "customerId", "value": "6" } );

这将生成一个 URL:

../server_processing.php?customerId=6

在您的服务器代码中,

$customerId = $_GET['customerId'] ;

应该返回值。您需要在 php 文件中进行更多调试以确定变量丢失的位置。很可能是拼写错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2014-11-26
    • 2015-09-26
    • 2018-09-02
    • 2023-01-04
    相关资源
    最近更新 更多