2013-10-28 511 views
1

我在php中使用jquery ajax執行刪除記錄。我想在不使用location.reload()函數的情況下刷新該內容。我試過這個,使用ajax jquery刷新頁面而不使用重載功能

$("#divSettings").html(this); 

但是,它不工作。在div中獲取更新內容的正確邏輯是什麼? 謝謝。

代碼:

function deletePoll(postId){ 
    $.ajax({ 
     type: "POST", 
     url: "../internal_request/ir_display_polls.php", 
     data: { 
      postId: postId 
     }, 
     success: function(result) { 
      location.reload(); 
      //$("#divSettings").html(this); 
     } 
    }); 
} 
+1

只要你的'ir_display_polls.php'頁面返回正確的html,你就可以使用'$('#divSettings')。html(result);'。 –

+0

當您使用'result'時,您正在使用'this'。 Html需要更新結果 – rogMaHall

+1

您收到的結果是什麼? HTML? – Lachezar

回答

1

就快:

function deletePoll(postId){ 
    $.ajax({ 
     type: "POST", 
     url: "../internal_request/ir_display_polls.php", 
     data: { 
      postId: postId 
     }, 
     success: function(result) { 
      $("#divSettings").html(result); // <-- result must be your html returned from ajax response 
     } 
    }); 
} 
+0

我試過那個..但它不是重新加載內容..刪除記錄後。它仍然顯示以前的內容,直到我不刷新頁面手動..... –

+0

'console.log($(「#divSettings」));'日誌? 「../ internal_request/ir_display_polls.php」的迴應是什麼? – kelunik

0

您只需要使用html的結果設置到您的 '#divSettings' 元素()函數:

$('#divSettings').html(result); 

所以一個完整的例子看起來像:

function deletePoll(postId){ 
    $.ajax({ 
     type: "POST", 
     url: "../internal_request/ir_display_polls.php", 
     data: { 
      postId: postId 
     }, 
     success: function(result) { 
      //Sets your content into your div 
      $('#divSettings').html(result);    
     } 
    }); 
} 
+0

我試過那個..但它沒有重新加載內容..刪除記錄後。它仍然顯示以前的內容,直到我不手動刷新頁面..... –

0

我相信你必須先清除該部分,然後才能再次附加HTML。像

function deletePoll(postId){ 
    $.ajax({ 
     type: "POST", 
     url: "../internal_request/ir_display_polls.php", 
     data: { 
      postId: postId 
     }, 
     success: function(result) { 
      //Sets your content into your div 
      $('#divSettings').html(""); 
      $('#divSettings').html(result);    
     } 
    }); 
} 

我相信這樣你就不會看到舊的內容。

相關問題