简体   繁体   English

错误处理SQL:TypeError:window.openDatabase不是一个函数

[英]Error processing SQL: TypeError: window.openDatabase is not a function

I have some strange issue in my code. 我的代码中有一些奇怪的问题。 i have create simple DB_Function.js to manage JS function inside html page. 我已经创建了简单的DB_Function.js来管理html页面中的JS函数。

i am calling function inside <body onLoad="CALL_DB()"> so first that will initialize the DB and create table if needed. 我在<body onLoad="CALL_DB()">内部调用函数,因此首先将初始化数据库并根据需要创建表。

Issue is here , 问题在这里,

  • Working : Chrome 工作:Chrome
  • Not Working : Android Mobile & Fire Fox 无法正常使用:Android移动版和Fire Fox

Code are as below : 代码如下:

DB_Function.js DB_Function.js

function CALL_DB() {
    try {
        alert("call_db");
        var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
        db.transaction(populateDB, errorCB, successCB);
    } catch (err) {
        alert("Error processing SQL: " + err);
    }
}


function populateDB(tx) {
    try {
        alert("call_table");
        tx.executeSql('DROP TABLE IF EXISTS DEMO');
        tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
        tx.executeSql('INSERT INTO DEMO (id, data) VALUES (3, "C")');
        tx.executeSql('INSERT INTO DEMO (id, data) VALUES (4, "K")');
    } catch (err) {
        alert("Error processing SQL: " + err);
    }
}


function errorCB(tx, err) {
    alert("Error processing SQL: " + err);
}

// Transaction success callback

function successCB() {
    alert("success!");
}

Test.html 的test.html

<!DOCTYPE html>
<html>
  <head>
    <title>Storage Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/DB_function.js"></script>

  </head>
  <body onLoad="CALL_DB()">
    <h1>Example</h1>
    <p>Database</p>
  </body>
</html>

Here is the my JS FIDDLE Please help me i don't know where i am wrong. 这是我的JS FIDDLE,请帮助我,我不知道我在哪里错。

Thanks for read my query. 感谢您阅读我的查询。

You are using Web SQL Database, which is not supported by Firefox . 您正在使用Web SQL数据库,而Firefox不支持 Also, the specification is abandoned by the W3C . 同样, W3C放弃了该规范

Have a look at IndexedDB ( caniuse ) instead. 看看IndexedDBcaniuse )。 There is also at least one shim to make IndexedDB work in browsers that only support Web SQL Database. 还有至少一种垫片可以使IndexedDB在仅支持Web SQL数据库的浏览器中工作。

The code "works" in this updated fiddle on Android Browser 4.1.2 . Android Browser 4.1.2此更新的小提琴中的代码“有效”。

Issue was here, 问题在这里,

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>

I have address a live js file to load so might be they was not able to load while launch the application. 我已经解决了要加载的实时js文件的问题,因此可能是因为它们在启动应用程序时无法加载。

So, I have save it locally in assets/www/js/cordova.js . 因此,我已将其保存在本地assets/www/js/cordova.js

So finally it looks like above and its working for me perfectly. 所以最后看起来像上面,它对我来说完美地工作。

 <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>

Look like your haven't initialize Cordova / PhoneGap API. 看起来您尚未初始化Cordova / PhoneGap API。 You must first listen to deviceReady event prior to manipulate the APIs 您必须先监听deviceReady事件,然后才能操作API

Look at the following doc: http://docs.phonegap.com/en/2.9.0/cordova_events_events.md.html#deviceready 查看以下文档: http : //docs.phonegap.com/en/2.9.0/cordova_events_events.md.html#deviceready

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 window.openDatabase抛出TypeError:对象[object DOMWindow]在Android上没有方法&#39;openDatabase&#39; - window.openDatabase throws TypeError: Object[object DOMWindow] has no method 'openDatabase' on Android 是var db = window.openDatabase &amp;&amp; openDatabase(); 避免错误的好方法? - Is var db = window.openDatabase && openDatabase(); a good way to avoid errors? 是否可以在Adobe AIR中使用localStorage和window.openDatabase? - Is it possible to use localStorage and window.openDatabase in Adobe AIR? Android 4.0.3,window.openDatabase无法运作 - Android 4.0.3, window.openDatabase doesn't work 如何从Android应用程序中托管的webView调用window.openDatabase? - How do I call window.openDatabase from a webView hosted in an android application? Ionic2错误类型“窗口”上不存在属性“ openDatabase” - Ionic2 error Property 'openDatabase' does not exist on type 'Window' 使用Cordova SQLite插件的window.sqlitePlugin.openDatabase方法时出现Javascript TypeError问题 - Getting issue of Javascript TypeError while using window.sqlitePlugin.openDatabase method of Cordova SQLite Plugin 错误:TypeError:window.attachEvent不是函数 - Error: TypeError: window.attachEvent is not a function Safari 7发生openDatabase错误 - openDatabase error at Safari 7 Mac Safari浏览器中的openDatabase错误 - openDatabase error in mac safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM