2012-11-10 51 views
4

我試圖使用預popuated數據庫的方法「的openDatabase」,但我不斷收到此錯誤:科爾多瓦-SQLitePlugin在PhoneGap的:遺漏的類型錯誤無法調用未定義

11-10 22:53:35.781: D/CordovaLog(20142): Uncaught TypeError: Cannot call method 'openDatabase' of undefined 
11-10 22:53:35.781: D/CordovaLog(20142): file:///android_asset/www/js/index.js: Line 8 : Uncaught TypeError: Cannot call method 'openDatabase' of undefined 
11-10 22:53:35.781: E/Web Console(20142): Uncaught TypeError: Cannot call method 'openDatabase' of undefined at file:///android_asset/www/js/index.js:8 

下面是代碼:
HTML

<html> 
     <script type="text/javascript" src="js/index.js"></script> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <title>Hello World</title> 
    </head> 
    <body onload="onLoad()"> 
     <div class="app"> 
      <h1>AAAA</h1> 
     </div> 
     <script type="text/javascript" src="cordova-2.2.0.js"></script> 
    </body> 
</html> 

JS:

function onLoad() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
} 

function onDeviceReady() { 
    var db = window.sqlitePlugin.openDatabase("test.db", "1.0", "testsstst", 20000); 
} 

這是爲什麼?

+0

看來你沒有正確安裝插件。 – AndiDog

+0

嗨奧馬爾,即使我現在有同樣的問題。你是如何解決這個問題的? – Vinod

+0

請在以下鏈接回答我的問題http://stackoverflow.com/questions/24737426/uncaught-typeerror-cannot-call-method-opendatabase-of-undefined-sqlite-plugin – Vinod

回答

3

你也應該包括在你的HTML「SQLitePlugin.js」是這樣的:

<body> 
... 
<script type="text/javascript" src="cordova.js"></script> 
<script type="text/javascript" src="SQLitePlugin.js"></script> 
... 
</body> 
相關問題