下面我用php编写了一个带有客户端的soap webservice的代码,它工作正常,实际上是php的新手,所以不知道如何从html页面向我的服务器php服务发布数据,我知道使用javascript它是可能的,但如何.....任何代码或有用的链接的帮助将不胜感激。
<?php
require_once "lib/nusoap.php";
function getProd($username,$password) {
$user = "root";
$pswd = "root";
$db = "LOGIN";
$conn = mysql_connect('localhost', $user, $pswd);
mysql_select_db($db, $conn);
//run the query to search for the username and password the match
$query = "SELECT * FROM PEOPLE WHERE USERNAME = '$username' AND PASSWORD = '$password'";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
//this is where the actual verification happens
if(mysql_num_rows($result) > 0)
$valid="LoginSucessful";
else
$valid="LoginFailed";
return $valid;
}
$server = new soap_server();
$server->configureWSDL("productlist", "urn:productlist");
$server->register("getProd",
array("username" => "xsd:string","password" => "xsd:string"),
array("return" => "xsd:string"),
"urn:productlist",
"urn:productlist#getProd",
"rpc",
"encoded",
"Get a listing of products by category");
if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);
#client of service#
<?php
require_once "lib/nusoap.php";
$client = new nusoap_client("http://localhost/expa/productlis.php");
$result = $client->call("getProd",array("category" => "admin","item" => "admin"));
Overall just need to pass parameter to the php function.
答案 0 :(得分:1)
从用户那里获取数据的方法很少:
通过网址参数传递数据:
<a href="index.php?foo=bar">Foo equals Bar</a>
<?php
$foo = (isset($_GET['foo'])) ? $_GET['foo'] : 'undefined';
echo "foo equals $foo";
?>
直接表格:
// index.php
// An example form that loops back to itself.
<form action="index.php" method="post" id="the_demo_form">
<fieldset>
<label for="foo">Foo</label>
<input type="text" name="foo">
</fieldset>
<input type="submit"/>
</form>
<pre>
<?php
// the $_POST global contains the data sent in the request.
var_dump($_POST);
?>
</pre>
<强>的Ajax 强> 如果您需要提交数据而不通过javascript重新加载页面,您将使用AJAX。 这是一个使用jQuery捕获表单提交事件并发送表单而不重新加载页面的示例。
// index.php
// An example form
<form action="index.php" method="post" id="the_demo_form">
<fieldset>
<label for="foo">Foo</label>
<input type="text" name="foo">
</fieldset>
<input type="submit"/>
</form>
<script>
$(document).ready(function(){
$("#the_demo_form").submit(function(event){
// This prevents the browser from following the form.
event.preventDefault();
// We take the data and send it to server via AJAX.
$.ajax({
// set this to server side script
url : "index.php",
data : $(this).serialize(),
success: function(data){
alert("eureka!");
}
});
});
});
</script>