首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MSIE 9中的"GET"ting AngularJS资源返回空数组

MSIE 9中的"GET"ting AngularJS资源返回空数组
EN

Stack Overflow用户
提问于 2014-04-04 19:13:15
回答 1查看 454关注 0票数 5

问题

当使用来自GET$resource请求时,成功的响应仅是9中的空数组。

测试

成功情景:

  • 使用FF或Chrome,GET请求将返回开发和本地环境中的数据数组。
  • IE9访问本地服务器时,"GET“请求返回一个数据数组。

失败的情景:

  • IE9访问开发服务器,则返回一个空数组。

调试步骤:

  • 在IE9中访问开发服务器:
    • 键入REST的URL将成功地返回一个数据数组。✓
    • 通过调试器验证发送到服务器的数据是否为数字和正确的值。✓
    • POSTing数据到另一个$resource可以正常工作--数据保存在数据库中并且是正确的。✓
    • 逐步遍历调试器将显示成功方法中的空数组。✗

结果

  • REST正在工作,因为直接请求返回数据。
  • 由于结果是以FF和Chrome格式返回的,因此角应该是工作的

问题

  • 还有其他技巧来调试这个问题吗?
  • 这可能是什么原因?
  • Ajax请求是否存在IE9特定的问题?

可能的相关资源

代码

资源

代码语言:javascript
运行
复制
var AnswerSetBySubjectByForm = function($resource) {
    return $resource('/rest/answerset/subject/:idSubject/form/:idForm',
            { idSubject : '@idSubject', idForm : '@idForm'},
            {'get' : {method:'GET', isArray:true}}
        );
};

控制器

代码语言:javascript
运行
复制
var AnswerSetController = function($scope, AnswerSetBySubjectByForm) {

...

  $scope.$on('loadAnswerSets', function(e, idSubject, idForm) {
    if (angular.isNumber(idSubject) && angular.isNumber(idForm)) {
      AnswerSetBySubjectByForm.get({ 
        idSubject : idSubject, 
        idForm : idForm
      }, function(answerSets) {
        /* answerSets is an empty array in IE9 only */
        $scope.answerSets = angular.copy(answerSets);
      });
    }
  });

...

应用程序

代码语言:javascript
运行
复制
...

app                
  .factory('AnswerSetBySubjectByForm', 
        ['$resource', AnswerSetBySubjectByForm])
  .controller('AnswerSetController', 
        ['$scope', 'AnswerSetBySubjectByForm', AnswerSetController])

...

任何帮助调试这将是非常感谢的!提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-08 06:41:07

在您的角度代码中这样做,以防止缓存GET请求。

代码语言:javascript
运行
复制
app.config(['$httpProvider', function ($httpProvider) {
    //Disable caching and make sure the call is made for each GET request.
    //Especially for IE, disable ajax get request caching
    $httpProvider.defaults.headers.get = $httpProvider.defaults.headers.get || {};
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22871236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档