title: jQuery POST to webservice via CORS
body: <p>I have read a lot of topics about CORS &amp; Javascript and about changing the headers in your post but I can't find the right example I am looking for. </p>
  
  <p>So I'm going to first up start with explaining the situation:</p>
  
  <ul>
  <li><strong>I can not change anything to the webserver since this is out of my reach (It's a SAP Cloud Portal)</strong></li>
  <li>I can only change the POST code, so I can only control what I send. </li>
  </ul>
  
  <p>The problem I have is described in the following Post:
  <a href="https://stackoverflow.com/questions/1099787/jquery-ajax-post-sending-options-as-request-method-in-firefox">jQuery $.ajax(), $.post sending &quot;OPTIONS&quot; as REQUEST_METHOD in Firefox</a></p>
  
  <p>--> My FF &amp; Chrome Headers send a METHOD OPTIONS instead of METHOD POST. </p>
  
  <p>I have written example code that works in IE but not in FF &amp; Chrome: </p>
  
  <pre><code>var dataString = "&lt;result&gt;&lt;firstname&gt;example&lt;/firstname&gt;&lt;lastname&gt;ThisIsSparta&lt;/lastname&gt;&lt;/result&gt;";
      var urlString = "http://delyo001.you.local:8000/sap/bc/youconsulting/ws/rest/anonymous/z_names_post";
  
      //Add TO SAP.
      var aData =  
              jQuery.ajax({
                  type: "POST",
                  contentType: "application/xml",
                  url: urlString,  // for different servers cross-domain restrictions need to be handled
                  data: dataString,
                  dataType: "text",
                  success: function(xml) { // callback called when data is received
                      //oModel.setData(data);             // fill the received data into the JSONModel
                      alert("success to post");
                  },
  
                  error: function(xml) { // callback called when data is received
                      //oModel.setData(data);             // fill the received data into the JSONModel
                      alert("fail to  post");
                  }
              });
          });
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>var invocation = new XMLHttpRequest();
  var url = 'http://delyo001.you.local:8000/sap/bc/youconsulting/ws/rest/anonymous/z_names_post';
  var body = '&lt;result&gt;&lt;firstname&gt;perthyrtyrtygop&lt;/firstname&gt;&lt;lastname&gt;sparta&lt;/lastname&gt;&lt;/result&gt;';
  
  
     invocation.open('POST', url, true);
     invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
     invocation.setRequestHeader('Content-Type', 'application/xml');
     invocation.send(body);
  </code></pre>
  
  <p>I have found 2 ways to fix this but without any examples:
  - do something with a proxy? 
  - send specific headers</p>
  
  <p>More information about my problem can be found at: 
  - <a href="http://scn.sap.com/message/13697625#13697625" rel="nofollow noreferrer">http://scn.sap.com/message/13697625#13697625</a></p>