XHR icon indicating copy to clipboard operation
XHR copied to clipboard

How to get Header information from a request?

Open lithiumlab opened this issue 8 years ago • 1 comments

Amazing library;

i wonder how to get Header information?

    xhr.POST(Alloy.CFG.api_url +'/authenticate', login_data, onSuccessCallback, onErrorCallback,opts);

function onSuccessCallback(e){
    Ti.API.info('AUTH DATA:', e);
}

Only brings the body. What about the Headers?

lithiumlab avatar Jun 25 '17 19:06 lithiumlab

Adding:

result.headers = xhr.getResponseHeaders();

https://github.com/raulriera/XHR/blob/master/xhr.js#L276

Solves it for uncached calls. But it needs to play nice with the cache writing process.

        var result = {};
        result.result = "cache";
        result.status = 304;
        result.headers = "cache";
        // not modified
        result.data = cache;
    onSuccess(result);

lithiumlab avatar Jun 28 '17 10:06 lithiumlab