HTML5/js sqlite数据库未进入事务功能
我有以下 javascript 函数:
function initDatabase() {
if (!window.openDatabase) {
alert('Databases not supported in this browser');
} else {
var shortName = 'TestDB';
var version = '1.0';
var displayName = 'HTML5 Test Database';
var maxSize = 1024 * 1024;
db = openDatabase(shortName, version, displayName, maxSize);
alert('opened db ' + db); //this says its a database
db.transaction(function (tx) {
alert('before create'); //never gets here
tx.executeSql('CREATE TABLE IF NOT EXISTS Person(FirstName TEXT, MiddleName TEXT, LastName TEXT);');
alert('after create');
});
alert('after transaction'); //does get here
}
}
在文档准备好时被调用:
$(document).ready(function () {
initDatabase();
});
正如您从注释中看到的,数据库似乎已创建/打开(但不确定如何验证这一点),但是当我尝试创建事务并执行一些 sql 时,该函数似乎从未被输入。
我做错了什么吗?我如何验证数据库是否存在?
我正在使用 Chrome 14 进行测试。
谢谢
I have the following javascript function:
function initDatabase() {
if (!window.openDatabase) {
alert('Databases not supported in this browser');
} else {
var shortName = 'TestDB';
var version = '1.0';
var displayName = 'HTML5 Test Database';
var maxSize = 1024 * 1024;
db = openDatabase(shortName, version, displayName, maxSize);
alert('opened db ' + db); //this says its a database
db.transaction(function (tx) {
alert('before create'); //never gets here
tx.executeSql('CREATE TABLE IF NOT EXISTS Person(FirstName TEXT, MiddleName TEXT, LastName TEXT);');
alert('after create');
});
alert('after transaction'); //does get here
}
}
being called on document ready:
$(document).ready(function () {
initDatabase();
});
As you can see from the comments, the database appears to be created/opened (not sure how I can verify this though) but when I attempt create a transaction and execute some sql, the function never seems to be entered.
Am I doing something wrong? How can I verify that the database even exists?
I am using Chrome 14 for testing.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
警报似乎是警告。它可能会暂停某些事情,导致它无法工作。
无论如何,
alert
被console.log
“取代”(在调试方面),如果我用日志替换警报,一切似乎都正常(我得到了所有四个日志) )。(要查看这些
console.log
调用,您可以按 F12 并单击“控制台”。)The alert seems to be the caveat. It might be suspending things causing it not to work.
alert
is "superseded" byconsole.log
anyway (in terms of debugging), and if I replace the alerts with logs, everything seems to work (I get all four logs).(To view these
console.log
calls, you can press F12 and click on Console.)