这是js文件的代码段>

$('#btnYes').on('click', (function() {
var id = $('#myModal').data('id');
var usertype = $('#myModal').data('usert');

$.ajax({

  url: '{site_url()}admin/deleteUserFromList',
  type: 'POST',
  data: {id: id, userT: usertype},
  success: function(html){

    $('[data-id='+id+']').parents('tr').remove();
    $('#myModal').modal('hide');
    alert('usuario borrado');
    window.location.reload();
  }
});
 return false;

}));

如您所见,从列表中删除用户后,会有一条警告消息。

我想在按下OK on Alert消息后刷新页面,所以我添加了以下行:
window.location.reload();

但这不起作用,为什么呢?我该如何解决?

我一直在尝试使用类似的替代方法
location.href = '....';

window.location = '/some/url';

但似乎没有任何效果!

这是在我的admin.php中,用于从数据库中删除用户的代码:
public function deleteUserFromList(){

    if ((isset($_POST['id']) && (isset($_POST['userT'])))){
        $rowId = $_POST['id'];
        $userType = $_POST['userT'];

        $result = array();

        if($userType == 'front'){
            $front = UserManager::getInstance()->getUser($rowId);
            UserManager::getInstance()->deleteItem($front);

        }else{
            $back = UserBackManager::getInstance()->getUser($rowId);
            UserBackManager::getInstance()->deleteItem($back);
        }
        $result["message"] = "Usuario eliminado";

        echo json_encode($result);
    }
}

最佳答案

为了在您的浏览器中模拟重定向,请尝试:
JavaScript方式:window.location.replace("http://stackoverflow.com"); jQuery方式:

var url = "http://stackoverflow.com";
$(location).attr('href',url);
试试这个,让我知道它对您是否有用。
编辑:
里面的ajax成功。尝试关闭模式窗口并尝试替换方法。
编辑2:
将这部分代码放入文档就绪块中,然后检查是否触发了该代码,这表示您的表单已正确重新加载。
$( window ).unload(function() {
  alert( "Bye now!" );
});

09-25 17:07
查看更多