weixin_33725270 2014-06-20 07:32 采纳率: 0%
浏览 30

数据表动态AJAX POST

Using Datatables with AJAX / POST, I initialize like this, where experiment_list is a list, and $("#type") is a selector menu.

var my_table = $('#my_table').DataTable( {
        "ajax": {"url": "/experiment_data/", "type":"POST", "data": {"experiments": experiment_list, "type": $("#type_selector").val() } },
"dom": '<"top">rt<"bottom"fp><"clear">', 
   } );

The problem I am having is that "type" is at initialization to the selector menu value, and changing the value after that and reloading the data, does not change the value in the "ajax" method.

$("#type_selector").change(function () {
    console.log($("#type_selector").val()); 
    position_table.ajax.reload()
    }); 

The API Documentation only has .url() for a dynamic method, which would mean either using GET (which is not very good for object type data) or rewriting views for each selector 'type' (and changing the url on select).

Is there a way to update the Data load of the Post request Dynamically?

  • 写回答

1条回答 默认 最新

  • weixin_33717298 2014-06-20 08:13
    关注

    Did you try with the sample request they provide ?

    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "/experiment_data/",
            "data": function ( d ) {
                d.experiments = experiment_list;
                d.type = $("#type_selector").val();
            }
        }
    });
    

    If it fails, can you provide the log of Firebug please ?

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!