2016-11-08 1 views
-1

몇 초마다 업데이트되고 페이지를 새로 고칠 필요가없는 타임 라인을 만들고 싶습니다 (서버에서 업데이트되는 별도의 파일에서 정보를 얻을 수 있음). 쉽게 JQuery를 만들 수 있습니까? 누구든지 웹 페이지에 예를 보여줄 수 있습니까? 데이터가 중요한 경우 10 초 간격으로 업데이트됩니다. 그리고 가능하면 나는 충실하고자하는 단지 CSS3 HTML5와 JQuery와10 초마다 업데이트되는 타임 라인

답변

1

아주 간단한 JS, 추가 정보를

// set interval 
var interval = setInterval(mycode, 10000); 
function mycode() { 
    // your ajax request or your function call to fetch data 
} 
function abortTimer() { // call to stop the timer 
    clearInterval(interval); 
} 

은 "10 초마다 업데이트"에 대한 jQuery를위한 필요가 없습니다 : great post about a similar queston

0
  1. 처음 수행 $.ajax 요청.
  2. 응답 데이터를 처리하고 success 또는 error에 표시하려면 refreshTimeline으로 전화하십시오.
  3. 10 초 기다렸다가 다시 Ajax를 보냅니다.

     function request() { 
         $.ajax({ 
         url: "your.php", 
         data: {}, //if there data to send 
         // recommended to use json and parse on success 
         //dataType:"json", 
         success: refreshTimeline, // try to refresh if success 
         error: refreshTimeline, // try to refresh if error 
         }); 
        } 
    
        function refreshTimeline(data) { 
         //handle data as you like 
         $("#time_line").html(data); 
         setTimeout(request, 10000); //wait 10 sec and request again 
        } 
    
        request(); // start ajax request 
    
    :

이 예제를 참조하십시오

관련 문제