Assuming http://example.com/js/script.js
fires an AJAX request against some relative URL, how do I get the absolute URL that ended up being requested?
For example, if I request image.png
from http://example.com/js/script.js
I'd expect to get back http://example.com/js/image.png
. If, however, I requested /image.png
from the same URL I'd expect to get back http://example.com/image.png
.
This question is tricky for two reasons:
I don't believe it's possible to get a script's URL from inside it.UPDATE: I incorrectly assumed that AJAX requests are issued relative to the script location. It turns out that they are issued relative tolocation.href
. This simplifies the situation.- I don't believe that
XMLHttpRequest
exposes the request URL, not to mention its absolute form.
Any ideas?