title: Cross domain AJAX Request with Sinatra not working - sending JSON with jQuery.ajax
body: <p>On my server in my sinatra app I have the following settings:</p>
  
  <pre><code>before do
    headers 'Access-Control-Allow-Origin' =&gt; '*',
            'Access-Control-Allow-Methods' =&gt; ['OPTIONS', 'GET', 'POST'],
            'Access-Control-Allow-Headers' =&gt; ['Content-Type', 'Accept', 'X-Requested-With', 'access_token']
  
    env['rack.errors'] = error_logger
  end
  </code></pre>
  
  <p>In my frontend app I perform the following http request:</p>
  
  <pre><code>$.ajax({
          type: "POST",
          url: "http://findaspot.multimediatechnology.at/api/",
          data: json,
          dataType: "json",
          success: function (data) {
              console.log('Success!');
              console.log(data);
          },
          error: function(xhr, status, error) {
              var err = eval("(" + xhr.responseText + ")");
              alert(err.Message);
          }
      })
  </code></pre>
  
  <p>I always get this error message:</p>
  
  <pre><code>XMLHttpRequest cannot load http://findaspot.multimediatechnology.at/api/. Invalid HTTP status code 404 
  </code></pre>
  
  <p>The error has something to do with a preflight OPTIONS request to the server - because I am sending JSON - I already tried to set the jQuery.ajax option "async" to false - didn't work either.</p>
  
  <p>So far I don't have any ideas how to solve this. Would be nice if you guys could help me out.</p>