admin管理员组文章数量:1326146
The callback function for the POST is returning null for my custom HTTP header X-Auth-Token
. Chrome is showing the correct POST response headers, but Angular.js is not.
The only ones Angular is returning are Cache-Control and Content-Type. Everything else shows null.
This is my CoffeeScript showing how I'm calling it:
.factory 'loginFactory', ($rootScope, $http, $resource) ->
$resource '/api/auth/login',
email: '@id'
password: '@id'
.controller 'userController', ($scope, $state, $http, loginFactory, userService) ->
$scope.validationError = false
$scope.user =
email: ''
password: ''
$scope.loginUser = ->
loginFactory.save $scope.user, (u, headers) ->
console.log headers('X-Auth-Token')
.$promise.then (response) ->
unless response.error
userService.login($scope.user.email, $scope.user.password)
unless userService.redirIfLoggedIn()
$scope.validationError = true
I also tried running earlier versions Angular 1.3.x, and those had the same issue.
Why is Angular only returning those two headers when I make a request?
The callback function for the POST is returning null for my custom HTTP header X-Auth-Token
. Chrome is showing the correct POST response headers, but Angular.js is not.
The only ones Angular is returning are Cache-Control and Content-Type. Everything else shows null.
This is my CoffeeScript showing how I'm calling it:
.factory 'loginFactory', ($rootScope, $http, $resource) ->
$resource '/api/auth/login',
email: '@id'
password: '@id'
.controller 'userController', ($scope, $state, $http, loginFactory, userService) ->
$scope.validationError = false
$scope.user =
email: ''
password: ''
$scope.loginUser = ->
loginFactory.save $scope.user, (u, headers) ->
console.log headers('X-Auth-Token')
.$promise.then (response) ->
unless response.error
userService.login($scope.user.email, $scope.user.password)
unless userService.redirIfLoggedIn()
$scope.validationError = true
I also tried running earlier versions Angular 1.3.x, and those had the same issue.
Why is Angular only returning those two headers when I make a request?
Share Improve this question edited Nov 26, 2014 at 2:33 Kevin Ghadyani asked Nov 26, 2014 at 0:09 Kevin GhadyaniKevin Ghadyani 7,3078 gold badges47 silver badges66 bronze badges 2- 1 Looks like the server needs to give permission to see the headers. Check out this stackoverflow./questions/17038436/… – dbugger Commented Nov 26, 2014 at 2:30
-
Ran it locally; it worked that way. Looks like that's the issue. In this instance:
Access-Control-Expose-Headers: X-Auth-Token
. – Kevin Ghadyani Commented Nov 26, 2014 at 17:14
1 Answer
Reset to default 7Thanks for this solution goes to @dbugger who mented the answer I needed:
Looks like the server needs to give permission to see the headers. Check out this: Reading response headers when using $http of Angularjs
The proper way to make headers available outside of your local domain is to set: Access-Control-Expose-Headers
on your webserver. In this particular case, you would put X-Auth-Token
.
本文标签: javascriptAngularjs saying custom HTTP response header is nullStack Overflow
版权声明:本文标题:javascript - Angular.js saying custom HTTP response header is null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742190295a2430086.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论