Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get request url from xhr object

Tags:

javascript

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.

like image 987
redsquare Avatar asked May 28 '09 14:05

redsquare


People also ask

How do I find the URL for my XHR?

open; xhrProto. open = function (method, url) { this. _url = url; return origOpen. apply(this, arguments); };


1 Answers

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

$.ajax({ ... 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.

like image 100
Ben Avatar answered Sep 20 '22 03:09

Ben