2017-02-19 54 views
0

我'試圖使一個AJAX調用刪除一行在表我的功能只是工作在Chrome和IE8中也沒有Firefox的AJAX刪除無法在某些瀏覽器工作

function delete_row(id) 
{ 
    if(confirm('Confirm to delete this Equipement ?')){ 
$.ajax 
({ 
    type:'post', 
    url:'edit_equipment.php', 
    data:{ 
    delete_row:'delete_row', 
    row_id:id 
    }, 
    success:function(response) { 
    if(response=="success") 
     { 
    var row=document.getElementById("row"+id); 
    row.parentNode.removeChild(row); 
    } 
    } 

}); 
} 
window.location.reload(); 
} 

回答

1

你沒有工作在告知瀏覽器開始 ajax請求後立即重新加載頁面。這可以防止請求被髮送,或者如果正在進行則中止它。它也會導致加載新頁面和刪除(如果它已被服務器接收)之間的競爭條件發生。

根本不需要reload,因爲您正在動態刪除該行。只要刪除

window.location.reload(); 

完全行。

但是如果你想反正調用它,那就不叫,直到請求完成後:

function delete_row(id) { 
    if (confirm('Confirm to delete this Equipement ?')) { 
     $.ajax({ 
      type: 'post', 
      url: 'edit_equipment.php', 
      data: { 
       delete_row: 'delete_row', 
       row_id: id 
      }, 
      success: function(response) { 
       if (response == "success") { 
        var row = document.getElementById("row" + id); 
        row.parentNode.removeChild(row); 
        window.location.reload(); // But again, you probably don't need it 
       } 
      } 

     }); 
    } 
} 
+0

,我需要重新加載頁面上展示其它compenents –

+0

更新的問題@ liane:然後就做上面的第二件事。 –

+0

或有任何方法可以確保請求完成,然後重新加載! –

相關問題