2013-10-17 2 views
0

코드는 다음과 같은 일을/이벤트 :Datatables 콜백 아래 빈 아약스 응답

  1. 일부 데이터를 얻을 수 getData.php에 요청을 보냅니다.
  2. 데이터를 검색하기 위해 서버 측 코드가 작동 중일 때 스피너가 표시됩니다. 데이터가 내 문제는 내가 데이터가 나지 않는 심지어 스피너를 숨기기 위해 수행하는 방법을 모르겠입니다

올 때

  • 스피너가 숨겨져 있습니다.

    JQuery와 코드 :

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

    2

    솔루션을 찾았습니다 :

    fnDrawCallback: function() { 
        var rows = this.fnGetData(); 
        if (rows.length === 0) { 
        spinner.stop(); 
        } 
    }, 
    
    0

    당신이 요소

    "fnRowCallback": function(e) {       
        console.log(e); // maybe there is a state of the response in it ;) ? 
        spinner.stop(); // Hide the spinner 
        } 
    
    을 검사하려고 : 데이터가없는 경우

    <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 문자열을 전송

    제대로 테스트 할 시간이 없습니다 ..