connecting to sqlite database from phonegap html file for android

让人想犯罪 __ 提交于 2020-01-05 09:24:11

问题


I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference i am using http://docs.phonegap.com/en/1.0.0/phonegap_storage_storage.md.html. My index.html is below

1.i have got phonegap.jar in lib

2.got phonegap.js in assests/wwww

3.got sqlite browser and sql shell downloaded in my hardisk

4.got jquery.min.js

I would like to know how to give the location of my sqlite from index.html so that it can make a connection with it. If I just pass in phonegap.js it is not making connection to sqlite.

<head>
 <title>Contact Example</title>
   <script type="text/javascript" charset="utf-8" src="js/phonegap-1.4.0.js">    </script>      
        <script type="text/javascript" src="js/jquery.min.js"/></script>
        <script type="text/javascript" src="js/jquery.mobile-1.0rc2.min.js"></script>
       <script type="text/javascript" charset="utf-8">
     function onLoad(){
       document.addEventListener("deviceready", onDeviceReady, true);
    var db = window.openDatabase("Dummy_DB", "3.0", "Just a Dummy DB",200000); 
            alert("db="+db); //not printing
 }
 function onDeviceReady(){
      navigator.notification.alert("doo");//only printing this


 }

 <body onload="c()">
  <h1>n Example</h1>
  <p>Database</p>
</body>

回答1:


There are couple of possible problems:

  • When you call openDatabase the document has loaded, but phonegap has not. The problem is that you call the method c() onBodyLoad not onDeviceReady as advised in the phonegap tutorial. See here.
  • Please also check you add the javascript accordingly. A very good way to check is to add the eventListener for deviceready. If it gets fired the javascript is loaded ok.


来源:https://stackoverflow.com/questions/9171662/connecting-to-sqlite-database-from-phonegap-html-file-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!