title: Using CORS for Cross-Domain Ajax Requests. Test on httpbin.org doesn't work
body: <p>I know that the issue already was discussed a lot. I went through the whole bunch of other SO's questions, but still has no solution.</p>
  
  <p>My test case is very simple.</p>
  
  <h3>Requirements</h3>
  
  <ul>
  <li>I need to get authorised on <strong>httpbin.org</strong> site from my local server (<strong>localhost:63342</strong>). Basically I use <strong><a href="http://httpbin.org/basic-auth/user/passwd" rel="nofollow">http://httpbin.org/basic-auth/user/passwd</a></strong> to test HTTP Basic Auth.</li>
  <li>I test <strong>Basic HTTP Authentication</strong> via <strong>jQuery.ajax</strong> function using GET request.</li>
  <li>I need to get this done using exactly REST because actually my <strong>real</strong> goal is to get authorised via REST API request on teamcity's server which uses GET requests.</li>
  </ul>
  
  <h3>What I have done so far</h3>
  
  <p>Actually I tried enourmous things (worked with headers(<strong>Access-Control-Allow-Credentials</strong>, <strong>Access-Control-Allow-Origin</strong>), tried to use <strong>beforeSend</strong> function, dealt with jsonP, etc). No luck.</p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="./jquery-1.11.0.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="target"&gt;
      Click here
  &lt;/div&gt;
  &lt;script&gt;
  $("#target").click(function() {
      var username = 'user';
      var password = 'passwd';
  
      $.ajax({
          type: "GET",
          beforeSend: function (xhr) {
              xhr.withCredentials = true;
              xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
          },
  
          // I know, this one is redundant
          xhrFields: { withCredentials: true },
          crossDomain: true,
          headers: { 'Access-Control-Allow-Credentials': true },
          headers: { 'Access-Control-Allow-Origin': '*' },
          // this one is redundant too
          headers: { 'Authorization': "Basic " + btoa(username + ":" + password) },
          //contentType: "application/json; charset=utf-8",
          dataType: 'jsonp',
          url: "http://httpbin.org/basic-auth/user/passwd",
  
          success: function(data, textStatus, jqXHR){
              alert('success');
          },
  
          error: function(jqXHR, textStatus, errorThrown ) {
              alert('failure');
          },
  
          // I don't know if I have to write it directly or not
          username: 'user',
          password: 'passwd'
      });
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h3>Results I get</h3>
  
  <p>During all my tests I got different results. The code above causes httpbin to show auth popup window to type credentials (it's weird because I send user/pass pair in headers). Another results I've got were: UNAUTHORIZED status (which is quite understandable), "error" error message (which is meaninless), etc...</p>
  
  <p>Experts of jQuery and cross-domain requesting, please help to figure out what should be done here.</p>
  
  <p>P.S. I know this is highly related to CORS issue, but I tried to set <strong>Access-Control-Allow-Origin</strong> in different ways without any success.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Actually my initial goal is to be able to invoke CI job from JS code (TeamCity job via REST API using Basic HTTP AUthentication).</p>
  
  <p>So, for TeamCity I believe there is a bug there (in REST API Plugin) - anyone who is interested in, please track the issue <a href="http://youtrack.jetbrains.com/issue/TW-35225" rel="nofollow">TeamCity's REST API Plugin doesn't allow to authenticate using Basic HTTP Authentication</a></p>
  
  <p>Regarding httpbin.org - test is invalid at all.</p>
  
  <p>Thanks a lot! </p>