2009-09-09 52 views
1

我的HTML是這樣追加數據加載的問題

<div id="rsContainer"> 
     <table id="rsTable"><!-- DATA HERE --></table> 
</div> 

,我的JavaScript是這樣

$('#UpdateAll').click(function() { 

     $('#status').fadeIn('500').text('Loading... This may take a while.'); 
     $.ajax({ 
     type: 'post', 
     url: 'func.php', 
     data: 'action=updateAll', 

     success: function(response) { 
      $('#response').fadeOut('500').fadeIn('500').append(response); 

      $('#rsTable').slideUp('1000').load('index.php #rsTable', function() { 
       $(this).appendTo('#rsContainer').slideDown('1000'); 
      }); 

      $('#status').fadeOut('500').empty(); 
     } 
     });  
    }); 

這工作正常,但經過appening的HTML看起來像這樣

<div id="rsContainer"> 
     <table id="rsTable"> 
      <table id="rsTable"><!--data--></table> 
     </table> 
</div> 

正如你可以看到它實際上附加到rsTable我該如何維護原來的結構?

謝謝。

+0

嘗試之前,其附加檢查響應值。它是否包含兩個rsTable表? – 2009-09-09 14:19:03

回答

0
$('#rsContainer').slideUp('1000').load('index.php #rsTable', function() { 
    $(this).slideDown('1000'); 
}); 

將slideUp id更改爲父ID。

1

在我運行的測試中,在.prepend()之前執行.emtpy()的速度比執行.html()要快200%。奇怪而真實。

如果你的意圖是同時擁有rsTable,你應該爲id添加一個計數器或者使用一個類,因爲id必須是唯一的。

看起來你想這樣做,但:

$('#rsContainer').empty(); 
$('#rsContainer').prepend($('#rsTable'));