如何通过额外的参数在ajax调用php使用jQuery数据表


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

如何通过额外的参数在ajax调用php使用jQuery数据表?

我的代码

 $(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