title: jQuery ajaxPrefilter fires after request is sent
body: <p>According to the description of <a href="https://api.jquery.com/jquery.ajaxprefilter/" rel="nofollow noreferrer">jQuery.ajaxPrefilter()</a>, it's supposed to get fired before the request is sent to <code>$.ajax()</code>, but from what I'm seeing in my project, the server API endpoint gets called first, then the <code>ajaxPrefilter</code> function is called at which point it's too late to make any changes.</p>
  
  <p>I'm probably missing something here, but I don't see it...</p>
  
  <p>Here's what my registration looks like:</p>
  
  <pre><code>$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
      if (options.url.startsWith('api') || options.url.startsWith('/api')) {
  
          if (options.headers === undefined) {
              options.headers = {};
          }
  
          if (!options.headers.Authorization) {
              var jwt = sessionStorage.getItem('accessToken');
              jqXHR.setRequestHeader('Authorization', 'Bearer ' + jwt);
          }
      }
  });
  </code></pre>
  
  <p>I'm fully aware that I can use <code>beforeSend</code> to set the headers, but I wanted to do it by first checking if the header exists, and if not, then add it, and the only way to read request headers before they're sent is only by using the <code>ajaxPrefilter</code> as far as I understand.</p>
  
  <p>I might just end up using <code>beforeSend</code>, but I got curious as to why this doesn't work the way it's described in the documentation? Maybe I'm not fully understanding how this works...</p>
  
  <p>I'm using jQuery version 3.3.1.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It seems like setting <code>async: false</code> fixes the problem, but that looks like a bug to me in jQuery.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I think I may have had some bug somewhere, because now the code above works. I have no idea where this bug could have been because it's not obvious at all by looking at my git changes, but it works for now... </p>