I am attempting to use PHP 5.2's SoapServer functionality. I setup soapserv.php as shown below. But I am lost as to how I can call the 'add' function with a language other than PHP (without WSDL). I want to make calls to it with AJAX (jQuery). Any help would be greatly appreciated!
<?php
function add($a, $b) {
return $a + $b;
}
$soap = new SoapServer(
null,
array('uri' => 'http://example.com/projects/php/soapserv/')
);
$soap->addFunction("add");
$soap->handle();
?>
And my JavaScript looks like this (tried several ways though).
var req = $.post("http://example.com/projects/php/soapserv", {"add":{a: 1, b: 2}});
req.done(function(msg){
document.write(msg.responseText);
});
req.fail(function(msg){
document.write(msg.responseText);
});
Got it... Just had to change the post data to a soap envelope!
var request = "<?xml version=\"1.0\"?>
";
request += "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">
";
request += "<soap:Body xmlns:m=\"http://example.com/projects/php/soapserv\">
";
request += "<m:add>
";
request += "<m:a>1</m:a>
";
request += "<m:b>2</m:b>
";
request += "</m:add>
";
request += "</soap:Body>
";
request += "</soap:Envelope>";
var req = $.ajax({
type: "POST",
url: "http://example.com/projects/php/soapserv",
data: request,
cache: false
});