title: Create custom function to extend default jQuery $.ajax
body: <p>I need to create a function that extends <code>jQuery</code> <code>$.ajax</code> callbacks.
  In specific, I need to <strong>add</strong> a default code to every <code>beforeSend()</code>, <code>complete()</code> callback.
  For instance, I have tried this:</p>
  
  <pre><code>var custom = {};
  var tempAjax = function(options,callback){ 
      var defaults = { };
      $.extend(options,defaults);
      return $.ajax(options);
  }
  custom.ajax = function() {
      if ( !arguments[0].beforeSend ) {
          arguments[0].beforeSend = function() {
              // my default code
          }
      }
      return tempAjax.apply($, arguments).then(function(value) {
          // my default code
      }).fail( function() {
          // my default code
      });
  }
  </code></pre>
  
  <p>it is important that every other <code>$.ajax</code> call will still run the own specific code in addition of the default code I have defined.
  So the following code:</p>
  
  <pre><code>custom.ajax({
      url:        url,
      data:       data,
      dataType:   type,
      beforeSend: function(result){   
          // other code
      },
      success: function(result){  
          // other code
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) { 
          // other code
      },
      complete: function () { 
          // other code
      }
  });
  </code></pre>
  
  <p>will run <code>// other code</code> <strong>and</strong> <code>// my default code</code> for each callback type.</p>
  
  <p>I'm not sure my solution is working as expected.
  Could you help me with that?</p>
  
  <p><strong>edit</strong>: it is also important that the default code will be used by <code>custom.ajax</code> and not by standard <code>$.ajax</code> calls that will continue to run normally.</p>
  
  <p>Thanks</p>