javascript
2013-12-10 19 views -3 likes 
-3
function checkStatusOfRequest(requestId) { 
    var filePath = ""; 
    $.ajax({ 
     type: "POST", 
     url: "<?php echo TESTMINE_APP_URL; ?>/ajax/check-export-status", 
     data: 'requestId=' + requestId, 
     dataType: "json", 
     success: function (data) { 
      if (data.exportType == 'csv') { 
       filePath = $("#csvFilePath").val(); 

      } else if (data.exportType == 'pdf') { 
       filePath = $("#pdfFilePath").val(); 
      } 

      if (data.status == 'downloadReady') { 

       fileName = data.fileName; 
       $("#statusDisplay").css("visibility", "hidden"); 
       $("#download").css("visibility", "visible"); 
       $('#requestId').val(requestId); 
       setTimeout(checkStatusOfRequest, 9000); 


      } 

     } 
    }); 
+0

格式代碼首先 – Sabari

+0

不要只粘貼代碼,請 –

回答

1
//keep the returned timeoutID 
var timeoutID = setTimeout(checkStatusOfRequest, 9000); 
.... 
//clear the timeoutID 
clearTimeout(timeoutID); 
+0

根據checkStatusOfRequest的checkStatusOfRequest功能clearTimeout的狀態 – Chaya

0

應該計時器設置爲變量第一

var statusTimer = setTimeout(checkStatusOfRequest, 9000); 

要清除計時器呼叫

clearTimeout(statusTimer); 
0

setTimeout()調用函數或毫秒

的指定次數後計算表達式
var myVar = setTimeout(function(){alert("Hi")},1000); 

setTimeout()返回的ID值用作clearTimeout()方法的參數。

clearTimeout(myVar); 
相關問題