Angularjs'$ http.get只在IE11执行一次 [英] Angularjs' $http.get only executed once in IE11

查看:665
本文介绍了Angularjs'$ http.get只在IE11执行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习angularjs,作为一个测试项目,我投票,返回活动进程(它们的PID)的列表的服务器,并显示这些。

I'm learning angularjs, and as a test project I'm polling a server that returns a list of active processes (their pids) and displaying these.

客户端code是这样的:

The client code looks like this:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="static/angular/angular.js"></script>
    <script>
      function ProcessCtrl($scope, $http, $interval) {
        $scope.ReloadData = function() {
          var result = $http.get("processdata", {timeout:1000});
          result.success(function(data,status,headers,config) {
            $scope.processes = data;
          });
        }
        $scope.ReloadData();
        var stop = $interval(function(){$scope.ReloadData()}, 1000);
      }
    </script>
  </head>
  <body ng-app>
    <div ng-controller="ProcessCtrl">
      Processes:
      <ul>
        <li ng-repeat="process in processes">
          {{process.pid}} is running
        </li>
      </ul>
    </div>
  </body>
</html>

这在Firefox和Chrome,但并不完全在Internet Explorer 11。

This works in Firefox and Chrome, but not quite in Internet Explorer 11.

所有的浏览器执行ReloadData方法每一秒,但IE11实际上不从服务器获取的过程数据。 Firefox和Chrome都每秒读取数据。我可以看到这个也从我的服务器,它记录每个请求的输出。

All browsers execute the ReloadData method every second, but IE11 doesn't actually fetch the process data from the server. Firefox and Chrome do fetch the data every second. I can see this also in the output from my server, which logs every request.

所有三种浏览器中执行 result.success 的code,但IE11保持在重新使用第一时间拿到了旧数据,其中Firefox和Chrome使用新获取的数据。

All three browsers execute the code in result.success, but IE11 keeps reusing the old data it got the first time, where FireFox and Chrome use the newly fetched data.

我检查Web控制台中的IE11的警告或错误,但有没有。

I've checked the web console in IE11 for warnings or errors, but there are none.

编辑:
由于所选择的回答表明,这是一个缓存的问题。我做了服务器'缓存控制'头添加到其值为无缓存的响应。这已经解决了这个问题。

As the chosen answer suggested it was a caching problem. I have made the server add a 'cache-control' header to the response with the value 'no-cache'. This has solved the problem.

推荐答案

这有可能是该请求被缓存,因为它是有效的缓存GET请求。 FF和Chrome可能有禁用缓存,因为运行的开发工具或其他原因。你可以附加一个时间戳URL查询字符串过程数据? +(新的Date())。的getTime(),看它是否是一个缓存的问题。

It's possible that the request is cached, as it is valid to cache GET requests. FF and Chrome probably have disabled caches, because of running dev tools or other reasons. You could append a timestamp as url query string "processdata?" + (new Date()).getTime() to see if it is a caching problem.

prettier方式prevent IE缓存可以在这里找到:
角IE缓存的问题为$ HTTP

Prettier ways to prevent IE caching can be found here: Angular IE Caching issue for $http

这篇关于Angularjs'$ http.get只在IE11执行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆