title: custom XMLHttpRequest.prototype.open
body: <pre><code>var open = XMLHttpRequest.prototype.open;
  
  XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) {
      this.addEventListener("readystatechange", function(event) {  
      if(this.readyState == 4){
         var self = this;
         var response = {
           method: method,
           uri: uri,
           responseText: self.responseText
        };
        console.log(response);  
      } else {
          console.log(this.readyState);
      }
      }, false);
    open.call(this, method, uri, async, user, pass);
  };
  </code></pre>
  
  <p>I am trying to listen for XHR before they are being sent. Something similar to jQuery's <a href="http://api.jquery.com/jQuery.ajax/" rel="noreferrer">beforeSend</a> in the <code>$.ajax</code> method.</p>
  
  <p>My goal is to listen for all XHR's before they are being sent. I suppose the closest thing would be to check above if <code>this.readyState === 1</code>?</p>
  
  <p>Would the code above cause any ajax libraries like jQuery to malfunction because I use prototype on <code>XMLHttpRequest</code>?</p>