In the jQuery docs regarding Deferreds, there’s this example of returning ajax args including jqXHR:
$.when( $.ajax("test.php") ).then(function(ajaxArgs){
alert(ajaxArgs[1]); /* ajaxArgs is [ "success", statusText, jqXHR ] */
});
But it seems that the docs are wrong. ajaxArgs is actually the response from the $.ajax call.
I need to get access to the jqXHR object because I need some meta data about the actual call, but it seems to be pretty hackish. This is what I’m currently doing, but there’s got to be a better way (crossing my fingers).
xhr = $.ajax({
'url': src,
}).done(function () {
var meta = xhr.getResponseHeader(...);
});
What’s the best/easiest way to get access to the jqXHR data that I need?
Use the third argument:
Note however that if you pass multiple deferreds into
$.when, it’l be the 3rd index of the first argument, second, or third depending on which request you want the headers of.