使用AJAX将数据参数传递给PHP,以便在数据表中进行服务器端处理

使用AJAX将数据参数传递给PHP,以便在数据表中进行服务器端处理

问题描述:

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

我正在使用服务器端处理数据表,但我想传递一个参数包含在我的数据表中 获取数据的PHP。 问题是我无法弄清楚如何传递它。 我知道如何使用“常规”AJAX,但该结构不适用于数据表。 p>

  var mydata =“xyz”; 
 $(“#full_table”  ).DataTable({
“processing”:true,
“”serverSide“:true,
”ajax“:{
”url“:”php / get_permit_data2.php“,
”type“:”POST  “,
”数据“:mydata //这实际上没有传递给我的PHP,就像通常使用AJAX一样。
},
 //等等
  code>  pre> \  n  div>

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