javascriptangularjsangularjs-resource

AngularJS: Unable to get responseHeaders after a $resource $save


I'm performing the following $save which calls my angularJS $resource and POSTs to my API. I'm able to debug into my success callback handler and the object is actually created in my API.

myObj.$save({}, function (value, responseHeaders) {
    myObj.someSuccessFunction();
}, function (responseText) {
    myObj.someFailureFunction();
});

I'm unable to retrieve anything from the "responseHeaders" param. "responseHeaders()" returns an empty object. I would like to pull the "location" response header like this: responseHeaders("Location").

It's worth noting that the Response is filled in when debugging in chrome. The "responseHeaders" object is failing to be populated for some reason.

How can we get these responseHeaders?

Thanks!


Solution

  • Could it be a CORS issue? If you are making the call across a domain, be sure to include cors.exposed.headers in the pre-flight OPTIONS call.