0

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

Here is my code

 $(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
            } );

        } );

I want to pass a new parameter to my php file and get a new result.

1
  • This question is very clear and should not be closed. Commented Jul 12, 2015 at 20:13

1 Answer 1

5

You can pass additional data by setting the ajax parameter to an object:

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

You can also pass data a function that receives the current data as an object which you can manipulate. This is especially useful for adding dynamic data that isn't available at page load.

Source: http://datatables.net/examples/server_side/custom_vars.html

Sign up to request clarification or add additional context in comments.

2 Comments

Happy to help. Don't forget to mark the correct answer.
Should I use this syntax "data": or this one data:?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.