【问题标题】:Datatable Server Side Ajax from API URL来自 API URL 的数据表服务器端 Ajax
【发布时间】:2016-08-26 18:39:31
【问题描述】:

我对一个 API 进行了 GET,然后我得到了 1000 个帐户。

我的样本数据:https://jsonblob.com/57c08bb2e4b0dc55a4f0eec7


由于Datatable website 建议,这里是我的设置

var account_table =  $('#account-table').DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": "scripts/server_processing.php",
  "deferLoading": 10,

});

对于“ajax”:“scripts/server_processing.php”,由于我使用的是API,我可以这样做吗

"ajax": "https://jsonblob.com/57c08bb2e4b0dc55a4f0eec7" ????

它会起作用吗?我希望有人能对此有所了解。

【问题讨论】:

    标签: php jquery ajax datatable


    【解决方案1】:

    你需要的是获取数据,而不是把 ajax 数据放在这样的地方

        var accounts;
        $.ajax({
             url: "https://jsonblob.com/57c08bb2e4b0dc55a4f0eec7",
          }).done(function(data) {
             accounts = data.data;
           }); 
         var account_table =  $('#account-table').DataTable({
           "processing": true,
           "serverSide": true,
           "ajax": accounts,
           "deferLoading": 10,
    
          });
    

    【讨论】:

    • 感谢您的帮助 - 伙伴 :)
    • 嘿,当我包含"deferLoading": 10, 时我得到No matching records found 怎么办?
    • 当我不包含时,它会显示全部 1000 个,但我第一眼只想加载 10 个。
    • 您能否详细说明一下,作为您回答的一部分?
    • datatables 看看这个
    猜你喜欢
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多