【发布时间】:2013-08-24 14:01:04
【问题描述】:
我创建了一个简单的网络服务,我希望 JQuery 能够使用网络服务。 Web 服务没有 XML 输出或 JSON 输出,所以我不知道如何使用 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