如何使用 jQuery DataTables 在对 php 的 ajax 调用中传递额外参数?

How to pass extra parameter in ajax call to php using jQuery DataTables?

如何使用 jQuery DataTables 在 ajax 调用 php 中传递额外参数?

这是我的代码

 $(document).ready(function() {
            var dataTable =  $('#student-grid').DataTable( {
                responsive: {
                    details: {
                        renderer: function ( api, rowIdx ) {
                            var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                                var header = $( api.column( cell.column ).header() );
                                return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                            } ).toArray().join('');

                            return data ?    $('<table/>').append( data ) :    false;
                        }
                    }
                },
                processing: true,
                serverSide: true,
                ajax: "borrowedBookNew.php" // json datasource
            } );

        } );

我想将新参数传递到我的 php 文件并获得新结果。

您可以通过将 ajax 参数设置为对象来传递其他数据:

$('#student-grid').dataTable({
    // ...
    ajax: {
        url: 'borrowedBookNew.php',
        data: {
            customField: 'customValue'
        }
    }
});

您还可以传递 data 一个函数,该函数接收当前数据作为您可以操作的对象。这对于添加页面加载时不可用的动态数据特别有用。

来源:http://datatables.net/examples/server_side/custom_vars.html