在iPhone应用程序中使用PhoneGap和jQuery无法获取JSON结果 [英] Cannot get JSON results using PhoneGap and jQuery on iPhone App

查看:165
本文介绍了在iPhone应用程序中使用PhoneGap和jQuery无法获取JSON结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用此代码:

<script type="text/javascript">

   $(document).ready(function() {
    var url =  "http://openexchangerates.org/latest.json";
    $.getJSON(url + "?callback=?", null,function(data) {

       var currencies = [ "USD", "EUR", "JPY", "GBP", "CHF", "AUD", "CAD", "EUR", "SEK", "HKD", "NOK", "NZD", "MXN", "SGD", "KRW", "RON", "BGN", "RUB", "PLN", "DKK" ];
       var myElementToAppendTo = $("#content");

       $.each(data.rates, function(key, value) {
         value2 = 1 / value;
         valueForEuro = value;  
         value = accounting.formatMoney(value, "", 4, ",", "."); 
         value2 = accounting.formatMoney(value2, "$", 4, ",", ".");

         euro = data.rates.EUR;
         value3 = valueForEuro / euro;
         value4 = 1 / value3;
         value3 = accounting.formatMoney(value3, "", 4, ",", "."); 
         value4 = accounting.formatMoney(value4, "&euro;", 4, ",", ".");

            if(jQuery.inArray(key,currencies) > -1) {
                myElementToAppendTo.append('<div class="currencyBox"><div class="currency">'+key+'</div><div class="tab1"><div class="half">'+value+'</div><div class="half">'+value3+'</div></div><div class="tab2"><div class="half">1 '+key+' = '+value2+' </div><div class="half">1 '+key+' = '+value4+' </div></div></div>');
            }
       });

    });
    });


</script>

它适用于任何浏览器本地/服务器,但当我构建一个iPhone应用程序的JSON结果不显示。任何想法为什么?

It works on any browser local/server but when I build an iPhone app the JSON results do not display. Any ideas why?

推荐答案

您需要将连接的服务器列入白名单(也可以是通配符)。
这是在您的PhoneGap.plist文件中完成。
从Phonegap文档:

You need to whitelist the server you are connecting to (this can be a wildcard as well). This is done in your PhoneGap.plist file. From the Phonegap docs:


此外,最新的代码具有新的白名单功能。如果您是
引用外部主机,您将必须在
PhoneGap.plist在ExternalHosts键下添加主机。通配符确定。因此,如果
你正在连接到http://phonegap.com,你必须添加
phonegap.com到列表(或使用通配符* .phonegap.com
也会匹配子域)。

Also, the latest code has the new white-list feature. If you are referencing external hosts, you will have to add the host in PhoneGap.plist under the "ExternalHosts" key. Wildcards are ok. So if you are connecting to "http://phonegap.com", you have to add "phonegap.com" to the list (or use the wildcard "*.phonegap.com" which will match subdomains as well).

这篇关于在iPhone应用程序中使用PhoneGap和jQuery无法获取JSON结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆