title: Send POST request to Rest WS with JS
body: <p>Im trying to send a REST request to a WCF Service with javascript.
  I have tried the service with a .net client and it works fine
  this is my example method in the wcf service:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method="POST", 
     ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
  bool GuardarJuan(Persona persona);
  </code></pre>
  
  <p>From javascript i have tried these methods:  </p>
  
  <pre><code>function sendRequest3(){
  var datos='{"IdPersona":2,"Nombre":"David BQ"}';
  var parameters = JSON.stringify(datos);
          var req=$.ajax({
              url: 'http://localhost:8732/Design_Time_Addresses/RestTEST/GuardarJuan',
              type: 'POST',
              data: parameters,
              contentType: 'application/json',
              dataType: 'jsonp'
          });
      }
  </code></pre>
  
  <p>And also like this:</p>
  
  <pre><code>function sendPost(){
      var url = "http://localhost:8732/Design_Time_Addresses/RestTEST/GuardarJuan";
      var persona={
          IdPersona: 2,
          Nombre: 'David BQ'
      };
      var parameters = JSON.stringify(persona);
      xmlHttp.open("POST", url, true);
      xmlHttp.setRequestHeader("Content-type", "application/json");
      xmlHttp.send(parameters);
      xmlHttp.onreadystatechange= function X()
          {
  
               if(xmlHttp.readyState == 4)
               {
                    alert(xmlHttp.responseText);
               }
          }
  </code></pre>
  
  <p>but none of this work.<br>
  It always give me a 405 error Method not allowed or 0x80004005 (NS ERROR FAILURE)</p>
  
  <p>Thanks</p>
  
  <p>EDIT:
  Problem solved.. It was the cross-domain problem.
  I was doing it with the VS Server, so I changed to IIS and everything worked fine</p>