1

I'm using server side processing for datatables, but I'd like to pass a parameter to be included in my PHP that gets the data. The problem is that I can't figure out how to pass it. I know how to do it using "regular" AJAX but that structure doesn't work with datatables.

var mydata = "xyz";
$("#full_table").DataTable({
            "processing": true,
        "serverSide": true,
                "ajax": {
            "url": "php/get_permit_data2.php",
            "type":"POST",
            "data": mydata //this doesn't actually pass something to my PHP like it does normally with AJAX.
            },
  //etc, etc
2
  • 2
    How are you trying to access the parameters in your PHP file? mydata appears to be a string when it should be an array/object. Post your PHP file too. Commented Apr 12, 2016 at 19:33
  • @Marcus You are exactly right. Totally forgot to make it an object. Thanks! Commented Apr 12, 2016 at 19:41

1 Answer 1

3

Use ajax.data option as shown below to pass static data.

$("#full_table").DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": "php/get_permit_data2.php",
    "type": "POST",
    "data": {
        "param_name": "param_value"
    }
  }
} );

You can pass dynamic data if you use function for ajax.data option as shown below:

$("#full_table").DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": "php/get_permit_data2.php",
    "type": "POST",
    "data": function(d){
         d.extra_search = $('#extra').val();
    }
  }
} );
Sign up to request clarification or add additional context in comments.

1 Comment

I also tried this . for me these custom value passing to server when add data to default search field only. If I only add values to custom field datatable not processing . pls advice

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.