我创建了一个简单的web服务,我希望JQuery能够使用webservice。webservice没有XML或JSON输出,所以我不知道如何用JQuery设置它。不过,webservice在PHP中可以很好地工作。我尝试将页面的标题更改为xml和JSON:("Content-Type:text/xml");和header('Content-type: application/json');如何设置它,以便JQuery可以使用webservice?
以下是完整的代码:
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();
}
?>发布于 2013-08-27 14:49:38
由于没有人回答这个问题,我用另一种方法解决了这个问题。我使用jakesankey的RESTful服务而不是SOAP,并以这种方式创建了。它的工作原理很好,也正是我想要的。
下面是指向PHP RestServer:https://github.com/jakesankey/PHP-RestServer-Class的链接
https://stackoverflow.com/questions/18419366
复制相似问题