I know this is an old question, but I just solved it.
What do we know about the situation? We know that jQuery no longer passes around the original XmlHttpRequest object, nor any references to it. We know that instead if passes around a "superset" that has most of the attributes. AND, we know that jQuery still uses an XmlHttpRequest to do the AJAX call.
So, if the browser still gets a callback and is passed the actual XmlHttpRequest, can we programatically access it? Using arguments.callee.caller
, Yes. We. Can.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee
By the time your hook fires (success
, fail
, whatever), you have just a few guarantees: You are in the callback callstack, the first function (the callback) has the XHR, and it has no caller
.
So, loop through the callstack (arguments.callee.caller.arguments.callee.caller...
) until the caller
is null
, then look at the arguments
! The first argument will be the callback Event object, and that event will have the XHR object created by the browser in the srcElement
attribute.
$.ajax({
url: 'https://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F',
type: 'get',
success: function(data, textStatus, jqXHR) {
var caller = arguments.callee.caller;
while(caller.arguments.callee.caller != null) {
caller = caller.arguments.callee.caller;
}
console.log(caller.arguments[0]);
console.log(caller.arguments[0].srcElement.responseURL);
}
});