php - $http headers is not a function - angularjs -


i posting data dynamics crm via soap on php server curl. after done giving entity guid in form of http response header. when attempting access via angular factory , $http.

my header exposed , able viewed in chrome developer tools , gives me guid need.

the code accessing promise data 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 is:

headers not function()

i can however, access header result such status 200 code using:

array.headers = headers; 

but need access custom header. ideas on how can achieve this?

as andy said already, headers 3rd parameter of success callback. have this:-

success(function(data, status, headers, config) {     // callback called asynchronously     // when response available   }) 

i wasn't going add answer doing wanted add headers indeed function.

in project, did below , saw function logged out type in console. function returns value of header item corresponding name passed, if no parameters passed, returns object containing 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 don't pass anything, returns object containing headers.              return response;         }); } 

excerpt 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; }; 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -