1
这是我的代码。
$scope.init = function() {
$scope.urlParam = $location.search();
if ($scope.urlParam.token == undefined || $scope.urlParam.id == undefined) {
$scope.is_start = false;
alert("您没有权限投票");
} else {
$http.get('/vote/validate_querystring?token=' + $scope.urlParam.token + "&id=" + $scope.urlParam.id)
.success(function (response) {
if (response.status == 3) {
$scope.is_start = false;
alert("您没有权限投票");
} else if (response.status == 4) {
$scope.is_start = false;
alert("您已完成投票");
} else {
$http.get('/vote/r_vote_setting')
.success(function (response) {
if (response.status == 1) {
$scope.is_start = false;
alert("投票尚未开始");
} else {
$scope.is_start = true;
$scope.voteData = response.data;
}
});
}
})
}
};
我ng-init
把这个功能,所以它会在每次页面加载时被调用。
正如你所看到的,在这个函数中有两个$http.get
。问题是,当我点击后退按钮回到此页面时,将从浏览器缓存中加载$http.get('/vote/validate_querystring?token=')
,而$http.get('/vote/r_vote_setting')
向服务器发出新请求。我从Chrome控制台找到了这个。
Request URL:http://localhost:8080/vote/validate_querystring?token=202cb962ac59075b964b07152d234b70&id=1
Request Method:GET
Status Code:200 OK (from disk cache)
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
Request URL:http://localhost:8080/vote/r_vote_setting
Request Method:GET
Status Code:200 OK
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
我想知道为什么会这样,以及如何使他们既回击按钮时发送请求到服务器,而不是缓存。
是否应响应* *曾经被缓存的请求?如果没有,请在服务器级别通过将其标记为不可缓存来解决此问题。 –
我使用tomcat作为服务器。我如何将它们标记为不可缓存? –
请参阅Tomcat文档并搜索如何使文档无法缓存(基本上,这是一些与缓存相关的标头)。 –