2016-11-01 2 views
0

나는이 기능을 가지고 :PHP JS 기능 시간 간격

그것이 ID randomtext 10 초마다 내 사업부로 notification.php에서 얻을 무엇로드
<script> 
    var auto_refresh = setInterval(
     (function() { 
       $("#randomtext").load("notification.php"); 
     }), 10000); 
</script> 

. 페이지가로드 된 후 1 초 후에 10 초마다 처음 실행되도록 할 수 있습니까?

답변

5

예 가능, 당신은 단지 당신의 setTimeout 외부 auto_refresh를 선언하는 경우 두 번째

<script> 
    // Run it for the first time after 1 second 
    setTimeout(function(){ 
     $("#randomtext").load("notification.php"); 
    }, 1000); 

    // Run it every ten seconds 
    var auto_refresh = setInterval(
     (function() { 
       $("#randomtext").load("notification.php"); 
     }), 10000); 
</script> 
+0

젠장. 당신은 쉽게 보였습니다. 그래도 고마워. 나는 아직 초보자입니다. –

+0

기꺼이 도와주었습니다. 정확하게 표시해주세요. :) – void

+0

10 분 기다려야합니다. y –

1

<script> 
     $(document).ready(function(){ 
      setTimeout(function(){ 
        loadNotification(); 
        var auto_refresh = setInterval(function() { 
          loadNotification(); 
        }, 10000); 
      }, 1000); 
     }); 

     function loadNotification() { 
       $("#randomtext").load("notification.php"); 
     } 

</script> 

을 시도 .load 1 일 이후에 호출 할 필요가 다음로드 호출은 9 갈 것입니다 초.

+0

이것도 아주 좋습니다! 감사 ! –