2

我有以下代码,它在Mozilla,Chrome上运行得非常好,但在Microsoft Edge或Internet Explorer上运行得不错。这是发生了什么。

当用户加载网页我触发下面的代码:

$http.get("/api/items") 
     .then(function (response) { 
      angular.copy(response.data, $scope.items); 
     }, function (error) { 
      $scope.errorMessage = error.statusText; 
     }) 
    .finally(function() { 
     $scope.isBusy = false; 
    }); 

其拉所有的值到<ul>。这部分在所有浏览器上正常工作。但是,当我触发以下一个:

$scope.interval = $interval(function() { 
     $http.get("/api/items") 
      .then(function (response) { 
       //success 

       //loop through the response 
       angular.forEach(response.data, function (value, key) { ... more code here} 

然后突然反应不再是从我的web api。我的意思是,当我调试我的应用程序并在我的GET api(我的意思是在Visual Studio中的MVC控制器下)中放置断点时,我无法看到Microsoft Edge触发的获取调用。

这里是什么样的网络检查员看起来像从Chrome中:

enter image description here

而这一次是从边缘:

enter image description here

据我了解,边有只发一个真正的XHR调用我的GET,剩下的只是从内存中缓存?

如何解决这个问题?为什么会发生这种情况?

回答

0

最后我发现,问题在于Angular存储Cache。有两个选项一个可以使用(从其他的StackOverflow职位采取):

1)角的方法(这对于未知的原因,我没有工作):

myModule.config(['$httpProvider', function($httpProvider) { 
    //initialize get if not there 
    if (!$httpProvider.defaults.headers.get) { 
     $httpProvider.defaults.headers.get = {};  
    }  

    // Answer edited to include suggestions from comments 
    // because previous version of code introduced browser-related errors 

    //disable IE ajax request caching 
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; 
    // extra 
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; 
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; 
}]); 

2)的ASP.NET方式装饰GET方法:

[ResponseCache(NoStore = true, Duration = 0)]