我正在尝试从我在应用程序中定义的拦截器服务中读取AngularJS的响应头值。
我在警告对话框中返回了未定义的内容,无法确定如何获取响应标头值“appVersion”。
response.headers()的JSON
{
"etag": "W/\"ca3-159d3673a17\"",
"content-type": "text/html; charset=UTF-8",
"content-length": "3235",
"accept-ranges": "bytes",
"cache-control": "public, max-age=0",
"last-modified": "Wed, 25 Jan 2017 02:14:34 GMT",
"date": "Mon, 30 Jan 2017 19:53:11 GMT"
}
{
"cache-control": "no-cache",
"pragma": "no-cache",
"content-type": "application/json; charset=utf-8",
"expires": "-1"
}
拦截器服务看起来像
app.service("versionCheckInterceptorService", ['$rootScope','$location', 'localStorageService', function ($rootScope,$location,localStorageService) {
return {
response: function (response) {
var swAuthToken = localStorageService.get('swAuthToken');
var appVersion = swAuthToken.appVersion;
alert(response.headers().appVersion); <---------Returns undefined
return response;
}
}
}]);
响应标头(来自浏览器检查器)
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 9461
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
appVersion: 1.1.1 <---------I need to get appVersion in AngularJS
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Date: Mon, 30 Jan 2017 19:10:44 GMT
我的方法是获取响应标头是否正确,我需要做些什么才能在我的应用中正确获取appVersion?