Javascript – Get request url from xhr object


Is there any way to extract the request url from an xhr object?
I can see the url in firebug via the channel property but you cant query this using javascript.

Best Solution

If you are using jQuery, you can make use of the "beforeSend" function in the AJAX request to modify the jqXHR object. I.e.,

url: "http://some/url",
beforeSend: function(jqxhr, settings) { jqxhr.requestURL = "http://some/url"; },

The jqXHR object passed to the various callbacks will then have that variable, jqXHR.requestURL, which you can access.