views:

53

answers:

2

Is it possible to intercept when the browser does a XHR? Regardless of JavaScript libraries used?

Like

setTimeout(function() {
  // jQuery XHT
  $('#container').load('foo.html');
}, 5000);

When the jQuery.load fires, I want to intercept this and add an url parameter to the request.

Thanks in advance for tips and info.

Best regards

tan

A: 

Not possible for all frameworks no, you'll have to do it on a per framework basis as they all build them differently. If this was only to be used by your own code then there is nothing stopping you writting a wrapper for you XHR calls which could tag the additional data on the end.

What is it you are wanting to send? A cache breaker? Tracking? Also why for all frameworks?

Also if you want to just debug the requests you can use Firebug in Firefox to see all XHR requests that get sent.

Pete Duncanson
A: 

Well each JQuery ajax methods return an XHR (except for load), so you could set your own onreadystatechange if you wanted to.

Gab Royer