使用 javascript 而不是 php 访问网络服务器
我现在正在使用phonegap 开发应用程序。我发现了一个类似的 php 代码,可以在这里访问本地服务器,但不幸的是,phonegap 不支持 php。
谁能帮我将下面的 php 代码“翻译”为 JQuery ajax 或任何其他 javascript 代码?谢谢!
require_once('nusoap.php');
/* create client */
$endpoint = "http://www.pascalbotte.be/rcx-ws/rcx";
$ns = "http://phonedirlux.homeip.net/types";
$client = new soapclient($endpoint);
// queryRcx is the name of the method you want to consume
// RcxQuery_1 is the name of parameter object you have to send
// x and y are the names of the integers contained in the object
$result = $client->call('queryRcx',array('RcxQuery_1' => array('x' => 12,'y' => 13)), $ns);
print_r($result);
I'm now using phonegap to develop a application. I have found a similar php code which can assess to a local server here, but unfortunately phonegap doesn't support php.
Can anyone help me to 'translate' the php code below into JQuery ajax or any other javascript code? Thanks!
require_once('nusoap.php');
/* create client */
$endpoint = "http://www.pascalbotte.be/rcx-ws/rcx";
$ns = "http://phonedirlux.homeip.net/types";
$client = new soapclient($endpoint);
// queryRcx is the name of the method you want to consume
// RcxQuery_1 is the name of parameter object you have to send
// x and y are the names of the integers contained in the object
$result = $client->call('queryRcx',array('RcxQuery_1' => array('x' => 12,'y' => 13)), $ns);
print_r($result);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
步骤 1. 解决与 http://www.pascalbotte.be/rcx 关联的 404 -ws-rpc/rcx?WSDL
步骤 2.获取 JavaScript SOAP 客户端。
步骤 3.
... ... ...
第 4 步:利润!
不过说真的。这一切真正需要的是一个基于 JavaScript 的 SOAP 客户端。虽然它们不是一打,但它们很常见。上面是针对 jQuery 的,但是很容易找到 其他 实现。
WSDL
定义导致 404 的事实可能是问题,也可能不是问题,因为实际的wsdl
定义在技术上是可选的,但您确实想弄清楚发生了什么。Step 1. Resolve the 404 associated with http://www.pascalbotte.be/rcx-ws-rpc/rcx?WSDL
Step 2. Get a JavaScript SOAP client.
Step 3.
... ... ...
Step 4. PROFIT!
Seriously though. All this really takes is a JavaScript based SOAP client. While they aren't a dime-a-dozen, they are pretty common. The one above is for jQuery, but it is easy enough to find other implementations.
The fact that the
WSDL
definition causes a 404 may or may not be a problem as the actualwsdl
definition is technically optional, but you really want to figure out what happened.您可以将此标头添加到 PHP 文件或 .htaccess 以避免跨域请求出现问题:
header('访问控制允许来源:*');
将 all(*) 替换为您的域名;)
祝您好运!
You can add this header to the PHP file or .htaccess to avoid problems with cross domain reqs:
header('Access-Control-Allow-Origin: *');
Replace the all(*) with your domain ;)
Good luck!