2011-03-24 5 views
0

의 실행 : 내가하고 싶은 것은 매 3 초 PHP 스크립트에 포스트 데이터입니다 http://plugins.jquery.com/files/jquery.timers-1.2.js.txtjQuery를 타이머 플러그인은 한 번만 대신 내가 jQuery를하고 jQuery를 타이머 플러그인을 사용하고 각 X 초

. 스크립트는 새 메시지가 있는지 확인하고 메시지가 있으면 새 메시지를 반환합니다. 타이머에 문제가 있습니다. 지금은 3 초 후에 한 번만 기능을 실행합니다. 한 번 실행 한 후에는 더 이상 실행되지 않습니다.

$(function() { 
$('.check').everyTime(3000, function() { 

var ID = $(this).attr("id"); 
    if(ID) { 
     $("#check"+ID).html('<img src="img/loader.gif" />'); 
    $.ajax({ 
     type: "POST", 
     url: "<?php echo $base;?>ajax_check_new.php", 
     data: "latestmsg="+ ID, 
     cache: false, 

     success: function(html){ 
      $("ol#msg").prepend(html); 
      $("#check"+ID).remove(); 
     } 
    }); 
} 

    }); 
}); 

의견이 있으십니까?

미리 감사드립니다.

+0

http://enfranchisedmind.com/blog/posts/jquery-periodicalupdater-ajax-polling/ –

답변

1

setInterval 대신 jQuery 타이머를 사용하는 이유가 있습니까?

편집 :

$(function() { 
    setInterval(function() { 
     var ID = $('.check').attr("id"); 
      if(ID) { 
       $("#check"+ID).html('<img src="img/loader.gif" />'); 
       $.ajax({ 
        type: "POST", 
        url: "<?php echo $base;?>ajax_check_new.php", 
        data: "latestmsg="+ ID, 
        cache: false, 

        success: function(html){ 
         $("ol#msg").prepend(html); 
         $("#check"+ID).remove(); 
        } 
       }); 
      } 
    }, 3000); 
}); 
+0

음, 그래, 절름발이 이유는 ... : 나는하지 않았다 jquery와 함께 사용하기 위해 호를 안다. –

+0

그 방법을 알고 계십니까? –

+0

나는 내 대답에 대한 편집을 참조하십시오. – mattsven

관련 문제