title: JQuery Ajax bad request to RESTfull API
body: <p>I'm trying to authenticate against demo webservices developed by a colleague of mine. 
  the Cross-origin resource sharing is allowed and works perfectly if I try to call from Advanced rest client plugin in Chrome. 
  but when I try to access with the code I get 500 server error</p>
  
  <pre><code>.ajax({ 
          type : "POST",  
          dataType: 'json',
          url: 'CANTPOSTTHISURL/rest/session',
          contentType: "application/json; charset=utf-8",      
          data: JSON.stringify({"username": "admin", "password": "admin" }),
          success: function(response)
          {
              console.log(response); 
          },
          error: function (data, status) {
              console.log( 'Sample of error data:', status );
              console.log("readyState: "+data.readyState+"\nstatus: "+data.status+"\nresponseText: "+data.responseText);
          },
          complete: function(xhr, status ) {
              console.log( 'COMPLETE');
          }   
    });
  </code></pre>
  
  <p>the errors I get are:</p>
  
  <pre><code>    OPTIONS CANTPOSTTHISURL/rest/session 500 (Internal Server Error) jquery.js:8475
  send jquery.js:8475
  jQuery.extend.ajax jquery.js:7930
  authenticate wts.js:5
  (anonymous function) wts.js:27
  jQuery.event.dispatch jquery.js:3045
  elemData.handle jquery.js:2721
  jQuery.event.trigger jquery.js:2957
  (anonymous function) jquery.js:3639
  jQuery.extend.each jquery.js:631
  jQuery.fn.jQuery.each jquery.js:253
  jQuery.fn.extend.trigger jquery.js:3638
  H jquery.mobile-1.3.0.min.js:2
  I jquery.mobile-1.3.0.min.js:2
  jQuery.event.dispatch jquery.js:3045
  elemData.handle jquery.js:2721
  OPTIONS CANTPOSTTHISURL/rest/session Invalid HTTP status code 500 jquery.js:8475
  send jquery.js:8475
  jQuery.extend.ajax jquery.js:7930
  authenticate wts.js:5
  (anonymous function) wts.js:27
  jQuery.event.dispatch jquery.js:3045
  elemData.handle jquery.js:2721
  jQuery.event.trigger jquery.js:2957
  (anonymous function) jquery.js:3639
  jQuery.extend.each jquery.js:631
  jQuery.fn.jQuery.each jquery.js:253
  jQuery.fn.extend.trigger jquery.js:3638
  H jquery.mobile-1.3.0.min.js:2
  I jquery.mobile-1.3.0.min.js:2
  jQuery.event.dispatch jquery.js:3045
  elemData.handle jquery.js:2721
  XMLHttpRequest cannot load CANTPOSTTHISURL/rest/session. Invalid HTTP status code 500 index.html:1
  Sample of error data: error wts.js:16
  readyState: 0
  status: 0
  responseText:  wts.js:17
  COMPLETE 
  </code></pre>
  
  <p>and the headers:</p>
  
  <pre><code>Request URL:CANTPOSTTHISURL/rest/session
  Request Method:OPTIONS
  Status Code:500 Internal Server Error
  Request Headersview source
  Accept:*/*
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8
  Access-Control-Request-Headers:accept, content-type
  Access-Control-Request-Method:POST
  Connection:keep-alive
  Host:CANTPOSTTHISURL
  Origin:http://127.0.0.1:8020
  Referer:http://127.0.0.1:8020/ppm/index.html
  User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
  Response Headersview source
  Access-Control-Allow-Origin:*
  Connection:close
  Content-Type:application/json
  Date:Mon, 31 Mar 2014 13:24:36 GMT
  Server:Wildfly 8
  Set-Cookie:GEAR=local-53185956500446bd39000020; path=/
  Transfer-Encoding:chunked
  X-Powered-By:Undertow 1
  ConsoleSearch
  </code></pre>
  
  <p>I think it is the data I'm sending but I also tried with '{"username": "admin", "password": "admin" }' or {"username": "admin", "password": "admin" } but nothing changes.
  an important remark: I can only do POST or OPTION requests so no jsonp 
  thank you</p>