title: Ajax Call To Web API
body: <p>I'm using jquery to make an ajax call to an asp.net Web API method that uses an authorization token for authenticating requests. Here is the ajax call:</p>
  
  <pre><code>$.ajax({
      url: targetUrl,
      type: 'GET',
      beforeSend: function(xhr){
          xhr.setRequestHeader("Authorization", "Basic " + btoa(token + ":" + password));
      },
      success: function (data) {
          // do stuff   
      }
  });
  </code></pre>
  
  <p>This call is resulting in an <code>405 Method Not Allowed</code> for the <code>OPTIONS</code> method. Which seems to be an issue with CORS support on the Web API. </p>
  
  <p>But, the Web API method works as expected if called from a simple .NET console app:</p>
  
  <pre><code>HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
  req.Headers[HttpRequestHeader.Authorization] = "Basic " + token + ":" + password;
  HttpWebResponse res = (HttpWebResponse)req.GetResponse();
  </code></pre>
  
  <p>It also works if called from Fiddler.</p>
  
  <p>If the Web API method does not support CORS, why do these other calls work? Am I missing something in my jQuery call?</p>
  
  <p>P.S. I do not have access to the Web API code base.</p>
  
  <p>Thanks in advance for the help!</p>