Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多次调用$http.get()总是返回缓存的结果_Javascript_Angularjs_Google Chrome_Jqxhr - Fatal编程技术网

Javascript 多次调用$http.get()总是返回缓存的结果

Javascript 多次调用$http.get()总是返回缓存的结果,javascript,angularjs,google-chrome,jqxhr,Javascript,Angularjs,Google Chrome,Jqxhr,我有一个角度控制器,通过$http对象进行重复获取,如下所示: $scope.refresh = function() { let url = 'api/get-status'; $http.get( url ).then( function( response ) { console.log( response.data ); }); }; $scope.intervalFunction = function() { $timeou

我有一个角度控制器,通过$http对象进行重复获取,如下所示:

$scope.refresh = function() 
{
    let url = 'api/get-status';
    $http.get( url ).then( function( response )
    {
        console.log( response.data );
    });
};

$scope.intervalFunction = function() 
{
    $timeout( function() 
    {
        $scope.refresh();
        $scope.intervalFunction();
    }, 2000 ) // msec
};

$scope.refresh();
$scope.intervalFunction();
回迁似乎发生了。当我在chrome中执行此操作时,我会在控制台中看到预期的结果-除了结果只是我从第一个结果中获得的相同内容的重复

更令人费解的是,我可以关闭服务器,代码继续运行,没有错误。当我查看chrome的网络视图时,chrome声称它将继续成功调用服务器


这就好像浏览器本身正在返回缓存的结果,并谎报其进行的回迁。

服务器在expires和max age头中返回了什么?是的,这就是问题所在。标题告诉浏览器缓存结果。奇怪的是,chrome网络标签仍然认为这些是有效的回迁,状态码是200,所有的东西都有。我在大小列中也得到了标记为“来自缓存”的200。你试过在你的“网络”选项卡中禁用缓存吗?我在服务器端修复了它。它不应该设置缓存头。你的洞察力是正确的。