2009-07-16 64 views
0

我有一個文件data.php,當用戶點擊更新時,數據庫在後臺更新與jquery,但作爲響應我想重新加載其數據更新的特定表。通過jquery加載同一個文件的元素

我的html:

<div id="divContainer"> 
<table id="tableContainer" cellspacing='0' cellpadding='5' border='0'> 
<tr> 
    <td>No.</td> 
    <td>Username</td> 
    <td>Password</td> 
    <td>Usage Left</td> 
    <td>%</td> 
</tr><!-- Multiple rows with different data (This is head of table) --> 

我的jquery:

$('#UpdateAll').click(function() { 
      $.ajax({ 
      type: 'post', 
      url: 'update.php', 
      data: 'action=updateAll', 

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

       $('<div id="divContainer" />').slideUp('500').empty().load('data.php #tableContainer', function() { 
        $(this).hide().appendTo('#divContainer').slideDown('1000'); 
       }); 
      } 
      });  
     }); 

一切正常數據庫得到更新,並在成功#response是越來越加載成功的消息,但表不清爽。

回答

0
 $('#UpdateAll').click(function() { 
     $.ajax({ 
     type: 'post', 
     url: 'update.php', 
     data: 'action=updateAll', 

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

      $('#divContainer').slideUp('1000').load('data.php #tableContainer', function() { 
       $(this).hide().appendTo('#tableContainer').slideDown('1000'); 
      }); 
     } 
     });  
    }); 
+0

它看起來起初這樣從問題複製,但仔細檢查我看到一些差異。你可以編輯這個來表明這是你改變的工作嗎? – 2009-07-16 18:42:48

0

您已經具有divContainer的ID的DIV,但你又創建這個元素

$('<div id="divContainer " />').slideUp.... 

你需要

$('#divContainer') 
     .slideUp('500') 
     .empty() 
     .load('data.php #tableContainer', function() { 
      $(this).slideDown('1000'); 
      }); 
相關問題