doujianguang5506 2016-04-12 19:26
浏览 36
已采纳

使用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
  • 写回答

1条回答 默认 最新

  • duan_2000 2016-04-12 19:47
    关注

    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();
        }
      }
    } );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?