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

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号