AJax删除在某些浏览器中不起作用

时间:2017-02-19 14:21:28

标签: javascript jquery ajax

我正在尝试进行AJAx调用以删除表格中的行,我的功能仅在Chrome中工作,并且在IE8和Firefox中都不起作用

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 个答案:

答案 0 :(得分: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
                }
            }

        });
    }
}