dataTables生成多个服务器端请求

时间:2013-03-18 13:31:04

标签: jquery-ui jquery jquery-plugins datatables

我正在使用dataTable jquery插件启用服务器端处理。使用fnReloadAjax函数时,隐藏处理div和显示新数据之间会有2-3秒的延迟。这是关于这个问题的post。 我发现这是由于datatable发出的多个服务器请求。

在我的页面onchange中,一组单选按钮正在调用服务器以获取新数据,如下所示

oTable.fnReloadAjax("getCaseList?caseStatus=xxx&showValidOnly=true");

在firebug控制台中,我看到两个请求一个接一个地发出

  1. GET https://localhost/getCaseList?caseStatus=xxx&showValidOnly=true&_=1363611652185
  2. GET https://localhost/getCaseList?caseStatus=xxx&showValidOnly=true&sEcho=4&iColumns=9&sColumns=&iDisplayStart=0&iDisplayLength=100&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&sSearch_8=&bRegex_8=false&bSearchable_8=true&iSortingCols=1&iSortCol_0=4&sSortDir_0=desc&bSortable_0=false&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=true&bSortable_8=true&_=1363611701804
  3. 处理div在第一次请求完成后被隐藏,但只有在第二次请求完成后才会加载新数据。

    为什么数据表会进行第二次额外通话?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。在我的情况下,我也一直在使用服务器端处理。 在数据表初始化之后,我编写了以下语句来隐藏一些列

tableExample.fnSetColumnVis(5, false);
tableExample.fnSetColumnVis(6, false);
tableExample.fnSetColumnVis(3, false);

我意识到它要求了4次。 然后我删除了这些行,在我的情况下解决了多个请求的问题。 如果你还想隐藏列,还有另一种方法是添加一个类('sClass':'hidden'),它将“display:none”设置为datatable列定义中的列。

  aoColumnDefs: [
        { "bSortable": true, "aTargets": [0] },
        { "bSortable": true, "aTargets": [1] },
        { "bSortable": false, "aTargets": [2] },
        { "bSortable": true, "aTargets": [3] },
        { "bSortable": true, "aTargets": [4] },
       { "bSortable": true, "aTargets": [5], "sClass": "hidden" },
        { "bSortable": true, "aTargets": [6], "sClass": "hidden" },
        { "bSortable": false, "aTargets": [7] },
        { "bSortable": false, "aTargets": [8] },
        { "bSortable": false, "aTargets": [9], "sClass": "hidden" }         

      ]

希望这会有所帮助。 感谢

答案 1 :(得分:0)

服务器端请求由内部_fnAjaxUpdate函数发出,该函数从_fnDraw调用。

这意味着您可能正在调用一些需要重绘表格的方法,例如排序或搜索,这会发出额外的请求。