小编HNQ*_*HNQ的帖子

如何使用$ resource读取响应头?

我正在使用$ resource从我的RESTful服务中获取数据,我需要读取响应头以获得分页的"X-Page"和"X-Total-Pages"值.

例:

Access-Control-Max-Age:1728000
Cache-Control:max-age=0, private, must-revalidate
Connection:Keep-Alive
Content-Length:2637
Content-Type:application/json
Date:Thu, 10 Apr 2014 16:53:01 GMT
Server:WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
Vary:Origin
X-Page:1
X-Per-Page:10
X-Total:17
X-Total-Pages:2
Run Code Online (Sandbox Code Playgroud)

但我无法从服务器获得完整的标头.

这是返回的标题: 在此输入图像描述

这是来自服务器的标头: 在此输入图像描述

这是我的代码:

.factory('TestAPI', ['$resource',
        function ($resource) {
            return $resource("http://ip.jsontest.com/?callback=showIP", {}, {
                query: {
                    method: 'GET'
                }
            });
        }])

TestAPI.query({}, function (value, responseHeaders) {
                console.log(responseHeaders());
            }, function (response) {
                console.log(response);
 });
Run Code Online (Sandbox Code Playgroud)

http-headers response-headers angularjs

7
推荐指数
1
解决办法
4793
查看次数

标签 统计

angularjs ×1

http-headers ×1

response-headers ×1