下面的代码做了以下事情:
- 向 getData.php 发送请求以获取一些数据。
- 当服务器端代码正在检索数据时会显示微调器。
- 数据到来时,微调器被隐藏
我的问题是,即使没有数据到来,我也不知道如何隐藏微调器。
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": []
}';