Reputation: 105220
Basically what the title says, I want to get the URL and HTTP Verb from a xhr. Is this possible?
Upvotes: 2
Views: 358
Reputation: 12524
Currently, there is no standard way to get HTTP verb or url from XHR object. But, W3C is considering getRequestHeader
for future considerations.
Upvotes: 1
Reputation: 344537
Not natively, I'm afraid. In prototypable implementations you could write your own prototype:
XMLHttpRequest.prototype.__oldOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.verb = "";
XMLHttpRequest.prototype.url = "";
XMLHttpRequest.prototype.open = function (verb, url, async)
{
this.verb = verb;
this.url = url;
this.__oldOpen.call(this, verb, url, async);
}
Don't expect it to work in IE7 and older though.
XMLHttpRequest
object, but it would take a lot of work to get it right:
var oldXHR = XMLHttpRequest;
function XMLHttpRequest()
{
var realXHR = new oldXHR();
this.onreadystatechange = function () {}
this.open = function (verb, url, async)
{
this.verb = verb;
this.url = url;
realXHR.open(verb, url, async);
{
this.send = function () { realXHR.send(); }
// all other properties and methods...
}
Of course, you have to go to the effort of correctly binding onreadystatechange
and setting the status
, etc.
Upvotes: 2