2013-10-06 46 views
1

我一直在尝试从我的AngularJS代码中调用外部API(Vimeo),但是我得到的所有内容都是304 Not Modified。 我的代码:

this.$scope.$safeApply(() => { 
    this.$http.jsonp('http://vimeo.com/api/v2/video/75532980.json?callback=?') 
     .success((r) => { 
      this.$log.info("Success: " + r); 
     }) 
     .error((e) => { 
      this.$log.info("Error: " + e); 
     }); 
}); 

奇怪的是,当我打电话对同一URL提琴手,似乎一切都确定,我得到了正确的JSON 200响应。

+0

在有看看这个SO:http://stackoverflow.com/questions/15956768/angularjs-is-caching-jsonp-by-default – jpmorin

回答

2

这里是一个工作plunker:http://plnkr.co/edit/PZ7rQXb3guREqGFsodHX?p=preview

我把答案来自:AngularJS is caching JSONP by default

您添加时间戳到您的查询,使其不被角缓存。另外,根据文档(AngularJS $http),我将您的回调值修改为JSON_CALLBACK。

指定请求目标的相对或绝对URL。应该包含JSON_CALLBACK字符串。

$http.jsonp('http://vimeo.com/api/v2/video/75532980.json?callback=JSON_CALLBACK&_=' + (new Date().getTime())) 
    .success(function (r) { 
     $log.info("Success: " + r); 
    }) 
    .error(function (e) { 
     $log.info("Error: " + e); 
    }); 
+0

非常感谢你,它的工作! – Arnstein