【问题标题】:How to bind datatable to ajax loaded tables?如何将数据表绑定到 ajax 加载的表?
【发布时间】:2016-07-14 13:21:57
【问题描述】:

我正在使用引导导航选项卡。选项卡内容是通过 ajax 加载的,并且在 ajax 加载的内容中有两个表。我想为这些表绑定数据表 jquery 插件,但我不知道如何。我知道我必须使用“委托”方法,但我知道在哪里以及如何使用。

谢谢。

【问题讨论】:

  • 你引用的是关于通过ajax加载数据表的数据,我问的是另一个问题。将数据表应用于通过 ajax 加载的选项卡的内容。
  • 谢谢,但这不是我的问题。

标签: jquery ajax datatable


【解决方案1】:

我认为你需要在 ajax ajax 完成后绑定它。这是一种方法。

    $.ajax({
        url: '/path/to/file',
        type: 'default GET (Other values: POST)',
        dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
        data: {param1: 'value1'},
    })
    .done(function() {
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {

        // after the ajax is complete, this function is 
        // called and you can bind the datatable function on your table
        $('#tableID').dataTable();

        console.log("complete");
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    相关资源
    最近更新 更多