Proposal: binding custon xhr.onreadystatechange handler in jQuery 1.4

Proposal: binding custon xhr.onreadystatechange handler in jQuery 1.4

We're currently looking at upgrading our application from jQuery 1.3 to 1.4 and are running in to an issue with the change in jQuery.ajax to use onreadystatechange directly instead of setInterval. In our code, in ajax beforeSend, we are binding our own onreadystatechange handler to inspect the xhr in readyState=4 to handle the response in advance of success/failure and complete being called:

  1.   jQuery.ajax($.extend({
  2.             beforeSend: function(xhr) {
  3.                 xhr.onreadystatechange = function() {
  4.                     if (xhr.readyState == 4) { //headers are ready
  5.                         if ("LOGIN" == xhr.getResponseHeader("LOGIN")) {
  6.                             xhr.abort();
  7.                             navigateToLoginPage();
  8.                         }
  9.                        // etc... 
  10.                     }
  11.                 };
  12.             }, requestSettings);

Due to the change, our handler is never being called, and I can't see any way to replicate the behavior. Moving our code to complete() wouldn't suffice since it needs to be handled before success/failure. Is there an advisable solution here?

One proposal would be to add an onreadystatechange handler to jQuery.ajax that would allow custom work to be done in response to readyState change. This would behave similarly to beforeSend, in that the function could return false to abort. I can submit a patch if this would be considered useful:

  1. //In jQuery.ajax function, line 5163
  2. var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
  3.     if ( s.onreadystatechange && s.onreadystatechange.call(callbackContext, xhr, s) === false ) {
  4.         complete();
  5.         if ( xhr ) {
  6.             xhr.onreadystatechange = jQuery.noop;
  7.         }
  8.     }
  9.     ///...

Thanks,
Jason