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

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码