2016-02-13 71 views
4

我有這個Ajax代碼來提交PHP表單。代碼的作品,但我想<div>內容應該改變刷新,而不整個頁面刷新。在AJAX表單提交後刷新Div的內容

div的ID是#container。

這裏是AJAX代碼:

$('.accept_friend').submit(function(){ 
     var data = $(this).serialize(); 

     $.ajax({ 
      url: "../accept_friend.php", 
      type: "POST", 
      data: data, 
      success: function(data) 
      { 
       //here is the code I want to refresh the div(#container) 

      }, 
      error: function(){ 
       alert('ERROR'); 
      } 
     }); 

     return false; 
    }); 
+0

'$('#container')。html(data)'不起作用? –

+0

@LucHendriks,只是使DIV空白 –

+1

這意味着沒有'數據' – adeneo

回答

5

你將不得不改變DIV的innerHTML屬性..用jQuery是做像這樣:

$('#container').html('... new content goes here...'); 

所以你的情況加在成功的功能:

$('#container').html(data); 

$('#container').html(data.someAttribute); 

取決於返回數據的類型和結構。