【问题标题】:Allow server-side caching in `fnServerData` in DataTables允许在 DataTables 中的 `fnServerData` 中进行服务器端缓存
【发布时间】:2013-08-05 05:27:22
【问题描述】:

默认情况下,DataTables 中的 Ajax 调用通过在 url 上添加虚假字段来避免缓存,例如http://yoursite.com/api/?_348522852542'。我想禁用它。似乎 ajax 函数调用了 fnServerData,它的定义是这样的......

    "fnServerData": function ( sUrl, aoData, fnCallback, oSettings ) {
        oSettings.jqXHR = $.ajax( {
            "url":  sUrl,
            ....
            "cache": false,
            ....
            });
      };

我希望"cache" 的值是true 而不是false。我错过了什么吗?为什么这样硬编码?进行此更改以在本地或通过提交补丁来编辑源代码的最佳方法是什么?

【问题讨论】:

    标签: jquery ajax datatables


    【解决方案1】:

    您可以覆盖 fnServerData 回调:http://datatables.net/usage/callbacks#fnServerData

    【讨论】:

      【解决方案2】:

      当已经缓存的数据(在 redis 中)被数据表(1.10.10)重新缓存时,这实际上帮助我解决了我的问题,这是我的代码(它也会刷新数据,因为它被缓存了,所以速度非常快):

      <script type="text/javascript" charset="utf-8">
              $(document).ready(function() {
                  var table = $('#issues-table').DataTable( {
                      processing : true,
                      ajax: {
                              url: '/jira',
                              dataSrc: 'issues',
                              cache: true
                      },
                      order: [ 0, 'desc' ],
                      fnRowCallback: function( nRow, aData, iDisplayIndex ) {
                          $('td:eq(0)', nRow).html('<a href="http://jira.com/browse/' + aData[0] + '" target="_blank">' +
                              aData[0] + '</a>');
                          return nRow;
                      },
                  } );
                  setInterval( function () {
                      table.ajax.reload( null, false ); // user paging is not reset on reload
                  }, 30000 );
              } );
      </script>
      

      【讨论】:

        猜你喜欢
        • 2012-08-09
        • 1970-01-01
        • 2014-04-06
        • 2012-09-29
        • 2014-06-24
        • 2014-12-02
        • 2016-12-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多