$ HTTP头不是一个函数 - angularjs [英] $http headers is not a function - angularjs

查看:1282
本文介绍了$ HTTP头不是一个函数 - angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 SOAP 我的PHP服务器上发布的数据动态CRM 卷曲。完成此操作后它给在HTTP响应头形式的实体 GUID 。当试图通过我的角度工厂访问此和 $ HTTP

I am posting data to Dynamics CRM via SOAP on my PHP server with cURL. After this is done it is giving the entity GUID in the form of a HTTP Response header. When attempting to access this via my angular factory and $http.

我的头被暴露,并且能够在Chrome开发人员工具来看待,并给我的 GUID 我需要的。

My header is exposed and is able to be viewed in Chrome Developer tools and gives me the GUID I need.

在code用于访问数据的承诺是:

The code for accessing the promise data is as follows:

        $http({
            method: 'POST',
            url: url,
            data: formData,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (data, headers) {

            var array = [];
            array.data = data;
            array.headers = headers('EntityId');
            console.log(array.headers);

            deferred.resolve(array);
        })

return deferred.promise;

//etc

我得到的错误是:

The error I get is:

头不是一个函数()

我可以然而,访问一些头部的结果,如通过使用状态200 code:

I can however, access some header result such as a status 200 code by using:

array.headers = headers;

但我要访问我的自定义标题。我如何能做到这一点任何想法?

But I need to access my custom header. Any ideas on how I can achieve this?

推荐答案

安迪已经说了,头是成功的回调的第3个参数。所以,你将不得不这样做: -

As Andy said already, headers is the 3rd parameter of the success callback. So you will have to do this:-

success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
  })

我不打算加入这个作为一个答案,但这样做,因为我想补充一点,头确实是一个功能。

I wasn't going to add this as an answer but doing this as I wanted to add that headers is indeed a function.

在我的项目,我没了下文,只见功能注销在控制台类型。该函数返回相应于通过,如果没有参数传递的名称的标题项目的值,返回包含所有标头的对象。

In my project, I did the below and saw function logged out as type in console. The function returns the value of the header item corresponding to the name passed, if no parameters are passed, returns an object containing all headers.

login(user) {
    return this.$http.post(this.url, user)
        .success((data, status, headers, config) => {
            console.log(typeof headers, 'headers'); => prints function
            console.log(headers(), 'headers'); => if you don't pass anything, returns an object containing all headers.

            return response;
        });
}

从角code摘录。

Excerpt from the angular code.

function headersGetter(headers) {
var headersObj;

return function(name) {
if (!headersObj) headersObj =  parseHeaders(headers);

if (name) {
  var value = headersObj[lowercase(name)];
  if (value === void 0) {
    value = null;
  }
  return value;
}

return headersObj;
};

这篇关于$ HTTP头不是一个函数 - angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆