2009-10-17 5 views
0
$(document).ready(function(){ 
var refreshId = setInterval(function() { 
    periodicRefresh(); 
}, 9000); 
}) 

. 첫째 IDS에서동적으로 테이블에 행 추가

<tr id="5094" style="background:White;"> 
    <td class="tdstd"> 
    </td> 
</tr> 

답변

3

"ajaxActions.php"에서 반환되고 AJAX 호출이 포맷됩니다. 또한, "currentfirstrow"는 모든 함수 내에서 액세스 할 수있는 글로벌 JavaScript 변수라고 가정합니다.

function periodicRefresh() 
{ 
    $.ajax({ 
     type: 'GET', 
     url: 'include/ajaxActions.php', 
     data: "action=displayLastEvent", 

     success: function(xml){ 
      var newfirstrow = $(xml).find("name_of_xml_node_that_contains_newly_returned_id").text(); 
      if(newfirstrow != currentfirstrow){ 
       //do add new row() 
      } 
     }, 
} 
+0

ajaxActions.php의 출력은 다음과 같습니다 Roch

+0

하지만, 또한 XML로 서식을 지정할 수 있습니다. – Roch

+0

아 좋아, 본질적으로 HTML을 출력하는 것입니다. 좋은 점은 조금 생각해 봅시다. – WesleyJohnson

1

숫자가 될 수 없습니다 : 여기

function periodicRefresh() 
{ 
    $.ajax({ 
     type: 'GET', 
     url: 'include/ajaxActions.php', 
     data: "action=displayLastEvent", 

     success: function(msg){ 
      var newid = $(msg).attr("id"); 
        current = $("#list tr:first").get(0).id; 
        if(newid != currentfirstrow){ 
         $("#list").prepend(msg); 
       lastrow = current-19; 
       $('#'+lastrow).remove(); 
        } 
     } 
    }); 
} 

테이블 행이 같은 모습의 예입니다. 그들은 편지로 시작해야하고 그 다음에 숫자가 와야합니다. 따라서 ID에 대해 다른 명명 규칙을 따라야합니다. 즉, 당신이 무엇을 요구하지만이 같은 뭔가 첫 번째 행의 ID를 얻을 수 있다면

나는 확실하지 않다 : 어떻게 XML 모른 채, 대답하기 조금 어렵다

$("table tr:first").get(0).id 
관련 문제