title: Call PHP SOAP web service from JQuery (Ajax)
body: <p>I have a PHP SOAP web service acting as a relay to call cross domain web services.  The problem I'm having is calling my local PHP web service methods from JavaScript (using JQuery/Ajax).  I want to call a specific method in my web service; e.g. "LoginToAccount"; </p>
  
  <p>I'm NOT interested in appending params in the url and then figuring out which method to call...  This is very straight forward in .NET (mywebservice.asmx/LoginToAccount") but can't figure it out how to get this to work in PHP.</p>
  
  <p>I continually get a "500 Internal Server Error" of "Bad Request":
  Bad Request</p>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>&lt;?php 
  
  function LoginToAccount($email, $passCodeHash) { 
      //...code calling cross-domain web services
      return $jsonEncodedResponse;
    }
  
  
  function CreateAccount($email, $passCodeHash){
      //...code calling cross-domain web services
      return $jsonEncodedResponse;
  }
  
  $server = new SoapServer(null, array('uri'  =&gt; "http://www.myurl/webservices/"));
  
  $server-&gt;addFunction('LoginToAccount');
  $server-&gt;addFunction('CreateAccount');
  $server-&gt;handle();
  ?&gt;
  </code></pre>
  
  <p>Here is my JavaScript code:</p>
  
  <pre><code>function AjaxCall() {
      $.ajax({
          type: "POST",
          url: "phpRelay.php/LoginToAccount",
          data: "{email : 'myEmail@email.com', passCodeHash: '12345'}",
          contentType: "application/json",
          dataType: "json",
          success: succeeded,
          error: queryError
      });
  }
  
  function succeeded(data, textStatus, request) {
      var result = $.parseJSON(data.d);
  
  }
  
  function queryError(request, textStatus, errorThrown) {
      alert(request.responseText, textStatus + " " + errorThrown);
  }
  </code></pre>
  
  <p>This is all on the same domain.  Thanks!</p>