在Phonegap中加载JSON?

基本上我有一个位于服务器上的PHP脚本,它生成一个JSON文件,列出了mysql数据库中的位置。 使用jQuery Mobile我正在开发一个应用程序来显示这些地方。 我的代码适用于Chrome和Safari,但是当我将其移植到Phonegap时,它无效。 我在互联网上搜索但找不到答案:(。

用于生成JSON(json.php)的php文件:

 

我的Javascript文件位于我的应用程序中(加载JSON并显示它):

 $('#places').bind('pageinit', function(event) { getPlaces(); }); function getPlaces() { var output = $('#placeList'); $.ajax({ url: 'http://www.mysite.com/json.php', dataType: 'jsonp', jsonp: 'jsoncallback', timeout: 5000, success: function(data, status){ $.each(data, function(i,item){ var place = '
  • '+item.name+'' + item.checkins+'
  • '; output.append(place); }); $('#placeList').listview('refresh'); }, error: function(){ output.text('There was an error loading the data.'); } }); }

    HTML看起来像这样:

     

    Places

    此代码适用于Chrome和Safari,但在使用Phonegap在xCode模拟器中运行时,它不会加载JSON。

    任何帮助将非常感激 :)

    这可能与白名单有关,Apple对任何类型的无法控制的数据(如iframe或feed)都不相信。 所以他们拒绝每一个外部联系。

    查看项目根文件夹(xcode)中的phonegap.plist,并将您的网站URL添加到数组’ExternalHosts’。 这可能会很好。