[英]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 , 问题在这里,
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. 看看IndexedDB ( caniuse )。 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.