Marten
Marten

Reputation: 1356

Retrieving the response headers in Dojo 1.6

how do I retrieve the response headers in Dojo 1.6? dojo.xhr returns a dojo.Deferred object and when I register a closure with then() the first argument contains only the response body. I know that the headers are in the ioArgs property but I cannot reach it from inside the closure. Am I approaching this in a wrong way?

Best regards, CQQL

Upvotes: 1

Views: 3342

Answers (2)

Marten
Marten

Reputation: 1356

So here is how I solved it using a closure:

var result = dojo.xhr(
    "GET",
    {
         url: "http://example.com"
    }
);

result.then(function (response) {
    console.log(result.ioArgs.xhr.getAllResponseHeaders());
});

But for a clean solution the ioArgs should definitely be passed as part of the response object.

Upvotes: 4

faken
faken

Reputation: 6852

Maybe you can do this:

var deferred = dojo.xhrGet({
    url: 'myurl',
    handle: function(res, io) { globalIOVar = io; }
});

deferred.then(
    function(res) {
        // Can access ioargs via globalIOVar...
    }
);

I don't think ioArgs are passed as second argument of closure passed to deferred.then, it would be easier, and would make more sense.

Upvotes: 1

Related Questions