0

我正在向这样的 API 发布有角度的 http 帖子

       $http({
            method: 'POST',
            url: 'http://api/ClientEndpoint',
            data: register,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            transformRequest: function (obj) {
                var str = [];
                for (var p in obj)
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                return str.join("&");
            }
       }).error(function (data, status, headers, config) {
           alert(data);
       });

返回以下响应

在此处输入图像描述

但我无法将响应路径存储在变量中。我怎样才能做到这一点?

这是跨域场景,这是 chrome 控制台中显示的响应 在此处输入图像描述

我想访问存储 ClientEndpoint 值

4

2 回答 2

0

你忘记.success(function (data) { })回调了吗?就像.error()你放在 http() 函数之后

我希望这能解决你的问题;)

于 2015-08-13T12:57:17.217 回答
0

.succes(response, headers)在您的或中使用 headers 变量.error(response, headers)

例如:

.success(function(data, status, headers, config) {
    //Success Handling
});

.error(function(data, status, headers, config) {
    //Error Handeling
});

这仅在您与服务器位于同一域时才有效,如果它是跨域的,则服务器必须Access-Control-Expose-Headers为您发送以使其工作。

于 2015-08-13T13:01:17.273 回答