-1

下面我用它的客户端在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.
4

1 回答 1

1

有几种方法可以从用户那里获取数据:

通过 url 参数传递数据:

<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>
于 2012-10-19T19:06:44.170 回答