Retrieving the response headers in Dojo 1.6

拟墨画扇 提交于 2019-12-11 07:58:47

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6335961/retrieving-the-response-headers-in-dojo-1-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!