0

下面的代码做了以下事情:

  1. 向 getData.php 发送请求以获取一些数据。
  2. 当服务器端代码正在检索数据时会显示微调器。
  3. 数据到来时,微调器被隐藏

我的问题是,即使没有数据到来,我也不知道如何隐藏微调器。

jQuery代码:

<script type="text/javascript">

$(document).ready(function() {

    var spinnerOpts = {
      // Options for the spinner here...
      ...   
   };

   var target = document.getElementById('spinn');
   var spinner = new Spinner(spinnerOpts);


    $('#myTable').dataTable( {
       "bProcessing": true,
       "sAjaxSource": "getData.php",
       "fnPreDrawCallback": function() {                    
         spinner.spin(target);    // Show the spinner
       },
       "fnRowCallback": function() {                        
       spinner.stop();   // Hide the spinner
      }

    } );
} );                

</script>

以下代码在没有数据时从 getData.php 发送一个 json 字符串:

echo '{
    "sEcho": 1,
    "iTotalRecords": "0",
    "iTotalDisplayRecords": "0",
    "aaData": []
}';     
4

2 回答 2

2

我找到了解决方案:

fnDrawCallback: function () {
  var rows = this.fnGetData();
  if ( rows.length === 0 ) {
     spinner.stop();
  }
},
于 2013-10-21T13:55:29.673 回答
0

你试图检查元素

   "fnRowCallback": function( e ) {                        
   console.log(e);   // maybe there is a state of the response in it ;) ?
   spinner.stop();   // Hide the spinner
  }

没有时间正确测试它..

于 2013-10-19T19:52:08.677 回答