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)]