Javascript 如何在数据表的服务器端处理脚本中使用$\u GET?

Javascript 如何在数据表的服务器端处理脚本中使用$\u GET?,javascript,php,datatables,Javascript,Php,Datatables,我正在使用这个示例的代码 我想在server_processing.php文件中使用$_GET变量,以便可以指定值并从url执行此操作。例如table.php?table id=table1 index.html <a href="table.php?table-id=table1">Table 1</a> <a href="table.php?table-id=table2">Table 2</a> <a href=

我正在使用这个示例的代码

我想在server_processing.php文件中使用$_GET变量,以便可以指定值并从url执行此操作。例如table.php?table id=table1

index.html

    <a href="table.php?table-id=table1">Table 1</a>
    <a href="table.php?table-id=table2">Table 2</a>
    <a href="table.php?table-id=table3">Table 3</a>

table.php

    <?php
    // Get
    $var = $_GET['table-id'];
    ?>
    <table id="example" style="width:100%">
        <thead>
            <tr>
                <th>Payslip ID</th>
                <th>Employee ID</th>
                <th>Employee Name</th>
            </tr>
        </thead>
    </table>
    <script>
    $(document).ready(function() {
        $('#example').DataTable( {
            "processing": true,
            "serverSide": true,
            "ajax": "scripts/server_processing.php"
        } );
    } );
    </script>

工资单ID
员工ID
员工姓名
$(文档).ready(函数(){
$('#示例')。数据表({
“处理”:对,
“服务器端”:正确,
“ajax”:“scripts/server_processing.php”
} );
} );
脚本/server_processing.php

    <?php
    // DB table to use
    $table = '$var';

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

    // indexes
    $columns = array(
        array( 'db' => 'first_name', 'dt' => 0 ),
        array( 'db' => 'last_name',  'dt' => 1 ),
        array( 'db' => 'position',   'dt' => 2 )
    );

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

    require( 'ssp.class.php' );

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

您需要使用该功能将
$\u GET['table-id']
的值传递给AJAX调用

ajax.data
选项提供向请求添加额外数据的能力,或者在需要时修改提交的数据对象

$('#示例')。数据表({
“处理”:对,
“服务器端”:正确,
“ajax”:{
“url”:“scripts/server_processing.php”,
“数据”:{
“表格id”:
}
}
} );

然后,
$\u GET['table\u id']
应该可以在
scripts/server\u processing.php

中找到可能的重复感谢。由于出现语法错误,我将php标记括在双引号内<代码>“表id”:“
$('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": "scripts/server_processing.php",
        "data": {
            "table_id": <?= $_GET['table_id'] ?>
        }
    }
} );