所以我有这样的服务:
.service("checkSystemStatus", ["$http", "statusUrl", function($http, statusUrl){
return $http({method: "GET", url: statusUrl, cache: false});
}])
使用此标记:
<li ng-mouseenter="checkStatus()">
<i class="fa fa-info-circle"></i>
<div class="info-container">
<h4>System Info</h4>
<table class="system-info">
<tr ng-repeat="(key, value) in systemInfo">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</table>
</div>
</li>
这一职能:
$scope.checkStatus = function(){
$scope.systemInfo = {};
checkSystemStatus.then(function(success){
$scope.systemInfo.running = success.data.jobs_running;
$scope.systemInfo.queued = success.data.jobs_queued;
$scope.systemInfo.cached = success.data.jobs_cached;
$scope.systemInfo.active_threads = success.data.threads_active;
$scope.systemInfo.server_address = success.data.server_address;
$scope.systemInfo.server_port = success.data.server_port;
console.log($scope.systemInfo);
})
}
问题是我总是为systemInfo获得相同的值,每当我悬停信息图标时,我在控制台中看不到任何XHR请求,除了第一个,这是在加载页面时发生的,而不是当我将鼠标悬停在标签上时。
到目前为止,解决这个问题的唯一方法是在url末尾添加一个参数,如
?time=unixtime
每次都要得到一个新的url,但是没有尾随参数的更干净的解决方案呢?有可能吗?
发布于 2014-09-12 09:50:33
它不仅依赖于"AngularJS"-Cache,而且还依赖于浏览器和服务器缓存设置。检查服务器在其响应中发送给客户端的缓存头类型。在REST-URL中添加一个“时间戳”参数是避免基于浏览器的缓存的一个技巧-是的。
但总的来说:这就是客户机-服务器通信的目的所在。我怀疑服务器发送了一些不同的、ETag、缓存过期等标题,它们将匹配。
发布于 2014-09-12 10:43:26
尝试将这些http头添加到服务器的响应中:
Cache-Control:no-cache, no-store, must-revalidate
Expires:-1
Pragma:no-cache
发布于 2014-09-12 10:49:58
试着像这样
.service("checkSystemStatus", ["$http", "statusUrl", '$q', function($http, statusUrl, $q){
this.GetData = function(){
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
return $http({
method: "GET",
url: statusUrl,
cache: false //no need to use this, caching is false by default
}).
then( function(response){
if (response.data) {
return response.data;
}
else
return $q.reject('Request failed');
});
}
}]);
控制器部分
$scope.checkStatus = function(){
$scope.systemInfo = {};
checkSystemStatus.GetData().then(function(data){
$scope.systemInfo.running = data.jobs_running;
$scope.systemInfo.queued = data.jobs_queued;
$scope.systemInfo.cached = data.jobs_cached;
$scope.systemInfo.active_threads = data.threads_active;
$scope.systemInfo.server_address = data.server_address;
$scope.systemInfo.server_port = data.server_port;
console.log($scope.systemInfo);
})
}
https://stackoverflow.com/questions/25805260
复制相似问题