0

I am making an angular http post to an API which like this

       $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);
       });

which is returning the following response

enter image description here

But I am not able to store the response path in a variable. How can I do that?

It is cross domain scenario and this is the response being showed in chrome console enter image description here

I want to access store the ClientEndpoint value

Harsh Vardhan
  • 111
  • 1
  • 14

2 Answers2

0

Did you forget the .success(function (data) { }) callback ? just like the .error() you put after the http() function

i hope this will solve your problem ;)

  • thanks Jean ....actually the response is in status 302 so its going through the error() and not success() – Harsh Vardhan Aug 13 '15 at 12:59
  • maybe this post could help you : http://stackoverflow.com/questions/18737674/handle-http-302-response-from-proxy-in-angularjs – Jean-Yves Delmotte Aug 13 '15 at 13:03
  • Either error or succes, there should always be a response. – Billy Aug 13 '15 at 13:03
  • 1
    Got it. its not really possible to catch the response of status 302 so that's it was not possible for me to store the response. I'll have to also write an interceptor for it. Am i right? – Harsh Vardhan Aug 13 '15 at 13:19
0

Use the headers variable in either your .succes(response, headers) or .error(response, headers).

E.g :

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

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

This only works if you are on the same domain as the server, if it's cross domain, the server has to send the Access-Control-Expose-Headers for you to make this work.

Billy
  • 1,104
  • 8
  • 22