【问题标题】:Calling web service using phonegap(ios)使用 phonegap(ios) 调用 Web 服务
【发布时间】:2012-02-21 14:26:02
【问题描述】:

我想在 phonegap 应用程序中调用网络服务。我正在使用

给出的演示代码

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 文件夹中。

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

【问题讨论】:

    标签: ios web-services cordova phonegap-plugins


    【解决方案1】:

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

    【讨论】:

    • 大家好,在解决了这个问题后,我写了一篇关于在PhoneGap中调用Web服务的博客kmithi.blogspot.in/2012/02/callling-web-services-in.html?
    • @ghostCoder,android 怎么样,我需要修复哪里。由于跨脚本限制而出现异常。那么我必须在哪里将 * 添加到 Android 中的 ExternalHosts 选项。谢谢。
    • 安卓没有这样的东西。它应该按原样工作。你得到什么错误
    • 我收到消息“Put Stuff in Me”,因为它是 :(。它应该已被替换。当我尝试使用 chrome 时,我得到了XMLHttpRequest cannot load http://ws.geonames.org/postalCodeSearchJSON?postalcode=90210&maxRows=10. Origin null is not allowed by Access-Control-Allow-Origin. 我们过去在访问托管服务时收到此错误在其他领域。我使用了相同的示例,没有更改任何内容。我所要做的就是类似于您为 iOS 提到的那个。
    【解决方案2】:

    试试这个例子:

    使用js编写这段代码并包含在index.html文件中或者使用javascript标签编写这段代码到html文件中。你必须在index.html中包含xui-2.3.2.js文件。 hmtl 只是为了减少代码长度。如果你不使用这个文件,那么 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 的权限。 在外部主机数组中添加 *。

    我相信它会完美运行。

    【讨论】:

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