title: jQuery ajax overwrite data/url beforeSend on specific url
body: <h1>Question</h1>
  
  <p>I wanna set a ajax setting for global ajax handled by jQuery</p>
  
  <h3>Condition:</h3>
  
  <p>If ajax url is 'www.example.com', the data (querystring or body) will append token.</p>
  
  <hr>
  
  <p>I tried two method</p>
  
  <h3>.ajaxPrefilter</h3>
  
  <pre><code>$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
  
      // Add data to ajax option
      if (options.url.match(/www\.example\.com/i) !== null) {
          originalOptions.data.token = 'i_am_token'
      }
  
  });
  </code></pre>
  
  <p>To add token when url is www.example.com-> it not work!</p>
  
  <p>In console/debugger originalOptions Object is added token property, 
  but request sent not having token parameter</p>
  
  <h3>.ajaxSetup / beforeSend Event</h3>
  
  <pre><code>$.ajaxSetup({
      beforeSend: function(jqXHR, settings) {
  
          // Only GET Method
          if (settings.url.match(/www\.example\.com/i) == null){
              settings.url.replace(/((\.\/[a-z][0-9])*\?+[=%&amp;a-z0-9]*)&amp;?token=[a-z0-9]*&amp;?([=%&amp;a-z0-9]*)/gi, "$1$3")
          }
  
      },
      data: {
          token: 'i_am_token'
      }
  });
  </code></pre>
  
  <p>And a reverse resolution, add token for each ajax request.</p>
  
  <p>Same as last one, settings.url changed by string replace in the console/debugger.
  But request still sent original url.</p>
  
  <hr>
  
  <p>Test in jsfiddle: <a href="http://jsfiddle.net/qVLN2/2/">http://jsfiddle.net/qVLN2/2/</a></p>
  
  <p>Thanks for your reading and help :)</p>