我想获得' X-Total-Count' RESTful API的响应头。在尝试在我的ngResource' User'的查询回调函数中获取标题时,似乎$ http忽略了很多响应标题。
这些是我的请求的响应标头:
Access-Control-Allow-Origin: *
Cache-Control: max-age=0, private, must-revalidate
Connection: close
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Fri, 17 Oct 2014 11:13:26 GMT
Link: <http://xxxx.xxx/user?page=2>; rel="next"
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Total-Count: 32
我在这里查询用户集:
User.query({
page: $scope.pagingOptions.currentPage,
limit: $scope.pagingOptions.pageSize
}, function(users, responseHeaders) {
console.log(responseHeaders());
console.log(responseHeaders('X-Total-Count'));
});
这是控制台的结果:
Object { cache-control="max-age=0, private, must-revalidate", content-type="application/json; charset=utf-8"}
null
那么为什么$ http的responseHeaders()函数只能转换10个标题属性中的2个?
答案 0 :(得分:0)
您确定没有进行跨域资源共享吗?
请参阅7.1.1 Handling a Response to a Cross-Origin Request
该规范禁止访问其他任何响应头字段 除了简单的响应头字段(即Cache-Control, 内容类型,...)