PhoneGap中的Cordova-SQLitePlugin:未捕获的TypeError无法调用未定义的方法'opendatabase'

时间:2012-11-10 20:59:54

标签: cordova phonegap-plugins typeerror

我正在尝试使用预先填充的数据库,但我一直收到此错误:

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);
}

为什么会这样?

1 个答案:

答案 0 :(得分:3)

您还应该在HTML中包含“SQLitePlugin.js”,如下所示:

<body>
...
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="SQLitePlugin.js"></script>
...
</body>