【问题标题】:External php page not loading in APK, but works in ripple emulator外部 php 页面未在 APK 中加载,但可在波纹模拟器中使用
【发布时间】:2024-01-07 15:24:01
【问题描述】:

我正在构建一个使用 jquery 移动导航的 phonegap 应用程序。我有一个外部 php 页面,它从 Db 查询项目并将它们加载到我的应用程序中。所以我正在使用

  $(document).delegate("#cardslist", "pageinit", function() {    
  $.mobile.changePage( "data/card-list.html", { transition: "fade",  changeHash: false });
      );
 });

其中 card-list.html 是一个内部页面,其内容是

$(document).delegate(".cardslist", "pageinit", function() {         
  $.ajax({
  method:'GET',
  url:'http://www.thecardguys.co.ke/m/card-list-mobile.php',
  beforeSend:function()
     {
  // $("#processing").show();
     },

 complete:function ()
   {
  //   $("#processing").hide();  
   },
 success: function(feedback)
   {
  $('.cardlist').html(feedback); 
  $('.cardlist').css({'transform': 'scale(0.6)'});                 
   }


  });
  }

http://www.thecardguys.co.ke/m/card-list-mobile.php 是一个外部 php 页面,用于获取数据并回显它。

内容在波纹模拟器中加载良好,但是当我捆绑应用程序时,数据不会加载。一周过去了

【问题讨论】:

    标签: jquery cordova jquery-mobile apk


    【解决方案1】:

    确保将 www.thecardguys.co.ke 添加到您的网络请求白名单中(请参阅whitelist plugin)。由于您请求的是非安全 url,因此您还需要为该 url 为 IOS9 设置传输安全性(将以下内容添加到您的 plist):

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>www.thecardguys.co.ke</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    

    或使 url 在 https 上运行。有关更多信息,请参阅How do I load an HTTP URL with App Transport Security enabled in iOS 9?) 和 Ajax Not working in IOS 9.0 Cordova 以及苹果 document on transport security is IOS9

    【讨论】:

    • 您好,谢谢您的回复,我已将网址添加到网络白名单中。但它仍然显示加载器但不加载提要。我试过https,这甚至没有在模拟器上加载。
    • @jonah 没有更多细节,我无法添加更多内容。由于您有一个 APK 并且没有自己构建它,因此很难获得任何调试信息。如果您可以使用 Cordova CLI 自己构建它,您可以使用 Safari 或 GapDebug (genuitec.com/products/gapdebug)。如果您使用的是 PhoneGapBuild,他们可以使用调试工具来确定出了什么问题 (docs.build.phonegap.com/en_US/…)。
    • 我没有使用任何 APK 调试器。让我试试 genuitec.com/products/gapdebug