Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 51413  / 15 Years ago, thu, may 28, 2009, 12:00:00

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.


More From » javascript

 Answers
0

I hope I'm understanding your problem correctly.



It should be fairly simple to wrap your XHR objects with your own object to allow for this kind of functionality.



Below is an overly simplified example:



// Assumption: GetXHR() returns a new XHR object, cross browser.

function HTTPGet(url, onStartCb, onCompleteCb)
{
var xhr = GetXHR();
// Construct your own xhr object that contains the url and the xhr object itself.
var myXhr = { xhr: xhr, url: url };

xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && xhr.status == 200)
{
onCompleteCb(myXhr);
}
};

xhr.open(GET, url);
onStartCb(myXhr);
xhr.send(null);
}


I haven't tested this extensively, but it should work and with some modifications (error handling, passing parameters, etc) you should probably be able to turn this example into a fully functional solution.


[#99438] Sunday, May 24, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradley

Total Points: 555
Total Questions: 102
Total Answers: 99

Location: Tajikistan
Member since Fri, Nov 27, 2020
3 Years ago
;