我正在尝试使用预先填充的数据库,但我一直收到此错误: 11-10 22:53:35.781: D/CordovaLog(20142): Uncaught TypeError: Cannot call method 'openDatabase' of undefined11-10 22:53:35.781: D/CordovaLog(20142): file:///android
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); }
为什么是这样?
您还应该在HTML中包含“SQLitePlugin.js”,如下所示:<body> ... <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="SQLitePlugin.js"></script> ... </body>