当前位置 : 主页 > 手机开发 > cordova >

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

来源:互联网 收集:自由互联 发布时间:2021-06-10
我正在尝试使用预先填充的数据库,但我一直收到此错误: 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>
网友评论