【问题标题】:Use PHP SoapServer in JQuery在 JQuery 中使用 PHP SoapServer
【发布时间】:2013-08-24 14:01:04
【问题描述】:

我创建了一个简单的网络服务,我希望 JQuery 能够使用网络服务。 Web 服务没有 XML 输出或 JS​​ON 输出,所以我不知道如何使用 JQuery 进行设置。该网络服务虽然可以与 PHP 一起正常工作。我试图将页面标题更改为 xml 和 JSON:("Content-Type:text/xml");header('Content-type: application/json'); 我如何设置它以便 JQuery 可以使用 web 服务?

这里是完整的代码:

SoapServer.php

header('Content-type: application/json');


function hello($name){
    return("hi" . $name);
}


$server = new SoapServer(null, array('uri'=>'http://localhost/PHPWebService/hello'));
$server->addFunction("hello");
$server->handle();


?>

SoapClient.php

<?php 
try{
    $client = new SoapClient(null, array(
            'location'=>"http://localhost/PHPWebService/SoapServer.php",
            'uri' => "http://localhost/PHPWebService/hello"

    ));

    $result = $client->hello("Bob");
    echo($result);


}catch(SoapFault $ex){
    $ex->getMessage();
}
?>

【问题讨论】:

    标签: php jquery web-services soap


    【解决方案1】:

    由于没有人回答这个问题,我已经用另一种方式解决了这个问题。我使用 jakesankey 的 RESTful 服务而不是 SOAP,并以这种方式创建了 JSON Web 服务。它工作得很好,正是我想要的。

    这里是 PHP RestServer 的链接:https://github.com/jakesankey/PHP-RestServer-Class

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多