AngularJS:响应头返回空对象

3

我正在使用AngularJS $http post方法的响应头来操作location参数。当我检查浏览器时,它显示响应头包含值为location参数,但当涉及到AngularJS响应头对象时,它根本不包含任何东西而是空对象。

$http.post(MNS_DOMAIN + SERVER.MESSAGE_PROXY, JSON.stringify(payload))
                .success(function(data, status, headers, config) {
            $scope.messageLocation = headers();

            $scope.success = SUCESS_DATA_SENT;
            clearFormData();
        })
                .error(function(errorCallback) {
            $scope.error = errorCallback;
            console.log("Error " + errorCallback);
        })
                . finally(function() {
            console.log("REST call for send message");
        });

        console.log($scope.error);
    };

如果你在控制台输出headers,它会给出什么? - Endre Simo
如果在控制台中打印它,会显示 [object Object] 并且属性为空。 - amlsoft
1
我通过在响应服务器中添加“Access-Control-Expose-Headers”:“Location”来解决了这个问题。谢谢。 - amlsoft
1个回答

0

我使用头部获取函数 - {function([headerName])} - 来完成这个。

你也可以像这样做:

var headerObject = data.headers();

and access the properties like headerObject["propertyName"] to get the value.

$http

{{链接1:$http}}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接