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

    报告相同问题?

    悬赏问题

    • ¥60 PCDN如何使用宽带的电视业务通道拨号叠加带宽?
    • ¥15 遇到这种校园宽带网络应该怎么样解决?
    • ¥30 AXI VIP验证多余打印问题
    • ¥15 利用加权最小二乘法求某品牌手机价格指标,已按照总销量计算出权重,各类型号手机价格已知,如何求得价格指标?
    • ¥15 如何自制一个硬件钱包,有兴趣的朋友一起交流
    • ¥15 (关键词-聊天软件)
    • ¥15 求大家看看这个编程的编法没有思路啊
    • ¥20 WSL打开图形化程序子窗口无法点击
    • ¥15 Jupyter Notebook 数学公式不渲染
    • ¥20 ERR_CACHE_MISS 确认重新提交表单