小编Ibr*_*rah的帖子

访问angularjs中的自定义http响应标头

服务器响应

我正在尝试访问标题'错误详细信息',您可以在浏览器网络检查器(上面的链接)中看到,标头返回.服务器方面我还将自定义标头添加到"Access-Control-Expose-Headers"以允许跨域请求,因为这被建议是对其他问题的修复.

以下是对服务器的请求以及成功/错误回调.

this.signon = function (request, onComplete, onError) {
    console.log("Calling server with 'login' request...");

    return $http.post("http://localhost:8080/markit-war/services/rest/UserService/login/", request)
        .then(onComplete, onError);
};

var onLookupComplete = function(response) {
    if (response.data.username)
    {
        //If user is returned, redirect to the dashboard.
        $location.path('/dashboard');
    }

    $scope.username = response.data.username;
};

var onError = function(response) {
    $scope.error = "Ooops, something went wrong..";
    console.log('error-detail: ' + response.headers('error-detail'));
};
Run Code Online (Sandbox Code Playgroud)

当我尝试访问响应头时,如下所示:

    console.log(response.headers());
    console.log('error-detail: ' + response.headers('error-detail'));
Run Code Online (Sandbox Code Playgroud)

这只输出:content-type:"application/json"error-detail:null

有没有理由将错误详细信息标头映射到响应对象?

javascript rest angularjs angular-http

10
推荐指数
2
解决办法
4140
查看次数

标签 统计

angular-http ×1

angularjs ×1

javascript ×1

rest ×1