2015-11-02 28 views
0

正常工作,出于某种原因,当我构建应用程序,并把它放在我的Android,但如果我在模拟器上运行它,它看起来和运行伟大的jQuery Mobile的将不会加载。请帮帮我。是否有任何额外的步骤需要采取措施使其工作或进行任何工作?jQuery Mobile的不PhoneGap的应用

<html> 
 
    <head> 
 
     <meta charset="utf-8" /> 
 
     <meta name="format-detection" content="telephone=no" /> 
 
     <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> 
 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
 
     <script type="text/javascript" src="cordova.js"></script> 
 
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> 
 
     <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
 
     <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
 
     <style> 
 
      #container 
 
      { 
 
       margin: 8px; 
 
      } 
 
     </style> 
 
     <script> 
 
     var xmlhttp; 
 

 
     window.onload=function() 
 
     { 
 
      document.addEventListener("deviceready", init, false); 
 
      //init(); 
 
     } 
 

 
     function init() 
 
     { 
 
      document.getElementById('btnHitServer').addEventListener('click', getServer, false); 
 
      xmlhttp = new XMLHttpRequest(); 
 
      xmlhttp.onreadystatechange = receiveServer; 
 
     } 
 

 
     function getServer() 
 
     { 
 
      xmlhttp.open('GET', 'http://app.mafialife.com/?email_debug=1', false); 
 
      xmlhttp.send(); 
 
     } 
 

 
     function receiveServer() 
 
     { 
 
      if(xmlhttp.readyState==4 && xmlhttp.status==200) 
 
      { 
 
       var json = jQuery.parseJSON(xmlhttp.responseText); 
 
       // console.log(json); 
 
       document.getElementById('Server').innerHTML = json.value.joke; 
 
      } 
 
     } 
 

 
     </script> 
 
     <title>Hit Server</title> 
 
    </head> 
 
    <body> 
 
     <div id="container"></div> 
 
     <h2>Connect To Server</h2> 
 
     <button id="btnHitServer">Hit Server</button> 
 
     <p>Press the button to Connect To Server</p> 
 
     <div id="Server"></div> 
 
    </body> 
 
</html>

回答

0

你真正应该下载JavaScript和CSS的jQuery和jQuery Mobile的,在你科尔多瓦项目使他们的本地资源。然后调整您的标签并指向本地版本。

不包括这些文件在本地会导致您的应用程序无法启动并工作应在设备处于脱机状态,并且应用程序试图远程下载在启动这些文件会引起不必要的性能问题。

如果您使用的是Cordova 5,启动时JS和CSS的远程加载也可能会阻止您的应用在真实设备上,Content Security Policy元标记需要配置为允许远程JS和CSS加载。然而,根据我以前的评论,您希望将这些本地应用程序捆绑到您的www文件夹某处的应用程序中(例如,在css和js子文件夹中,具体取决于您的项目结构如何),因为我说过的原因并不是最佳做法。

+0

所以我现在是本地存储jQuery的,但它在运行应用程序时仍然不会加载。 – Dave

+0

您是否添加了一个设备准备事件监听器,并在回调函数中启动您的应用程序?科尔多瓦还没有准备好,直到事件发生。 –

+0

我不确定。我将如何做到这一点? – Dave