3

我想在 phonegap 应用程序中调用 Web 服务。我正在使用给出的演示代码

http://wiki.phonegap.com/w/page/32513809/Simple-Web-Service-Consumption-with-PhoneGap-and-XUI

我从链接创建了 xui.js

http://xuijs.com/downloads/xui-2.3.2.js

并尝试将 xui.js、index.html 放在 www/assets 和 www 文件夹中。

但这对我不起作用。有人可以帮助我吗.....

4

2 回答 2

5

尝试将 * 添加到 PhoneGap.plist 中的 ExternalHosts 选项
如果您的应用无法连接到互联网/拨打 xhr 电话,可能会出现这种情况

于 2012-02-21T14:43:51.620 回答
0

试试这个例子:

使用js编写这段代码并包含在index.html文件中或者使用javascript标签将这段代码编写到html文件中。您必须在index.hmtl中包含xui-2.3.2.js文件这只是为了减少代码的长度.如果你不使用这个文件,那么 x$ 将不起作用。

        x$.data = {};
        x$(window).load(function(e){
          x$("#returned_information").xhr("http://ws.geonames.org/postalCodeSearchJSON?postalcode=90210&maxRows=10", 
            { callback: function(){
                var codes = eval("("+this.responseText+")").postalCodes; /* this should be an array */
                x$("#returned_information").html(codes[0].placeName);
              }
            }
          );
        });

这在 index.html 正文中

      <h1 id="returned_information">
          Put Stuff in Me
      </h1>

最后在外部主机的属性列表文件中授予打开 URL 的权限。在外部主机阵列中添加 *。

我相信它会完美运行。

于 2012-04-04T06:58:09.937 回答