title: JQuery Ajax POST request to remote web service
body: <p>I somehow can't figure it out, the situation is as follows:</p>
  
  <p>I'm calling a method on a web service that is not on the same machine and use the following JS snippet in my script:</p>
  
  <pre><code>$.ajax({
              type: "POST",
              url: "http://" + gServer + "/xawebservice/xawebservice.asmx/" + webMethod,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              cache: false,
              async: false,
              data: WSParameters,
              success: function callFunction(result) { processResults(result, pType, pParam1); },
              error: function (xhr, status, error) {
                  alert(error.toString());
                  //alert(xhr.toString());                    
          }
          });
  </code></pre>
  
  <p>Parameters are fine and tested, the web method is also correct.</p>
  
  <p>As an error message I get this:</p>
  
  <ul>
  <li>Firefox: [Exception... "Failure"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: http://<code>localhost</code>:7515/jquery-1.8.3.js ::  :: line 8434"  data: no]</li>
  <li>Chrome: Error: NETWORK_ERR: XMLHttpRequest Exception 101</li>
  <li>IE8: No Transport</li>
  </ul>
  
  <p>If I'm using the same snippet on a web service that is running on the same machine, there is no problem. And if I use the remote web service over the web interface, it's also working fine.</p>
  
  <p>PS: I googled around a bit and some pages were recommending some cross domain parameters, which didn't work either. Unfortunately using a relative path will not work I guess.</p>
  
  <p>Thanks for any efforts in advance.</p>
  
  <p>Br
  vm370</p>
  
  <p>UPDATE:
  Alright I updated my code to execute a CORS request based on my existing one, but I get an error 500, executing the request on the server directly is working fine and CORS is activated on the server.</p>
  
  <pre><code>function xenappRequest(pType, pParam1) {
  
  // CORS request    
  var url = "http://" + gServer + "/webservice/webservice.asmx/webMethod";
  var params = { "appName": pParam1 };
  var xhr = createCORSRequest("POST", url);
  if (!xhr) {
      alert('CORS not supported');
  } else {
      // Do the request
      // Response handlers.
      xhr.onload = function () {
          //var text = xhr.responseText;
          alert('Response from CORS request to ' + url + ': ' + xhr.response);
      };
      xhr.onerror = function () {
          alert('Woops, there was an error making the request.');
      };
      xhr.send(JSON.stringify(params));
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
      // Check if the XMLHttpRequest object has a "withCredentials" property.
      // "withCredentials" only exists on XMLHTTPRequest2 objects.
      xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
      // Otherwise, check if XDomainRequest.
      // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
      xhr = new XDomainRequest();
      xhr.open(method, url);
  } else {
      // Otherwise, CORS is not supported by the browser.
      xhr = null;
  }
  return xhr;
  </code></pre>
  
  <p>}</p>
  
  <p>From FF i get the error 500, in IE8 the request lands in the xhr.onerror clause...
  Any ideas?</p>