Consume Simple SOAP Service
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
function validateForm() {
event.preventDefault();
var bookName = $("#name").val();
//AJAX call to call server script to fetch data
$.ajax('./client.php', {
type: 'GET', // http method
data: { name: bookName }, // data to submit
success: function (data) {
//appending data to output div element
$("#output" ).append(data+ "<br>");
},
error: function (ex) {
$("#output" ).html('error while fetching data');
}
});
}
</script>
</head>
<body>
<form name="myForm" onsubmit="validateForm()">
Cost of Book:
<input type="text" name="name" id="name">
<input type="submit" value="submit" id="submit">
</form>
<div id='output'></div>
<br>
</body>
</html>
<?php
require 'lib/nusoap.php';
//input wsdl file respective to the service that you are using
$client = new nusoap_client("http://localhost:8888/rest/service.php?wsdl");
$bookName = $_GET['name'];
$price = $client->call('getPrice', ["find"=>$bookName]);
if(empty($price)){
echo "Book information not available";
}
else{
echo $price;
}