2015-11-02 30 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