0

我的解锁方法永远不会在更改 url 时被调用。关闭浏览器执行该方法。关闭选项卡不会执行该方法...我得出这个结论是因为服务器端没有收到任何帖子(通过检查控制台)。

/* Callback function that unlocks the current time report when leaving the angular app */
    $window.onbeforeunload = function (event) {
        event.preventDefault();
        if ($scope.reportData != undefined && $scope.reportData.superId != undefined && !archive) {
            $http.post(Settings.timereportBaseURLhttp + 'monthlyreport/' + $routeParams.office + '/current/' + $routeParams.tmsstep + '/' + $scope.reportData.superId + '/unlock');
        }
    };
4

1 回答 1

0

首先,除非$window引用window,请尝试删除$. 其次,event.preventDefault()不会阻止浏览器卸载窗口。在大多数浏览器中,它只会询问用户是否想离开页面。如果用户选择不停留在页面上,并且 AJAX 调用还没有完成,浏览器可以立即关闭它,这样你就不会在服务器端收到任何 POST 请求。

为了实现我认为您正在尝试做的事情,如果服务器在合理的时间内没有收到 ping ,我会每隔一段时间 ping 服务器并解锁报告。

于 2013-10-10T08:20:57.053 回答