我正在从服务器(SpringBoot)发送一个笨拙的标头->>
SpringBoot:
response.addHeader("headerToken", "valueToken");
response.addHeader("Access-Control-Allow-Origin","*");
response.addHeader("Access-Control-Allow-Methods","GET");
response.setHeader("Access-Control-Expose-Headers","Custom-Header");
return new ModelAndView("redirect:" + url);
我的回报是"http://...path...AngularJS...etc"
我的流程不 AngularJS调用SpringBoot并返回AngularJS,所以我做不到->
$http.get('Springboot').
success(function(data, status, headers, config) {
...
})
.error(function(data, status, headers, config) {
...
});
我的流程如何不正常AngularJS-> Springboot-> AngularJS我无法从AngularJS的http.succes ...中获取标头。
然后我想用JS在控制器中获取标头->
angular.module('don').controller('Dona', ['$rootScope', '$scope', '$http', '$cookies', '$routeParams', '$window', '$location', function ($rootScope, $scope, $http, $cookies, $routeParams, $window, $location) {
var self = this;
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
console.log(headers);
console.log("---");
req .addEventListener("readystatechange", function () {
if (this.readyState == this.HEADERS_RECEIVED)
console.log(this.getAllResponseHeaders())
});
console.log("***");
// Load get data
...etc
}]);
(this.readyState为null)
结果是->
https://i.stack.imgur.com/mDpGS.png
我需要10个repu才能显示img您可以看到我添加了-> response.setHeader("Access-Control-Expose-Headers","Custom-Header");
...
我如何读取我的valueToken?
请参阅此img pls->
https://i.stack.imgur.com/LmfXK.png
(我需要10个repu才能显示img)