最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Datatables Dynamic AJAX POST - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Jun 20, 2014 at 7:57 user3467349 asked Jun 20, 2014 at 7:32 user3467349user3467349 3,1915 gold badges40 silver badges64 bronze badges 2
  • which v. of datatables ? – Kalzem Commented Jun 20, 2014 at 7:47
  • Version 1.10 of datatables. – user3467349 Commented Jun 20, 2014 at 7:56
Add a ment  | 

1 Answer 1

Reset to default 4

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 ?

发布评论

评论列表(0)

  1. 暂无评论