gpt4 book ai didi

cordova - Uncaught ReferenceError : dbb is not defined at file:///android_asset/www/index. html(Phonegap)

转载 作者:行者123 更新时间:2023-12-02 08:25:51 25 4
gpt4 key购买 nike

我有一段用 Phonegap 编写的基本代码,用于在 sql lite 表中插入值。但是当我尝试按下此操作的按钮时,日志显示消息:“ Uncaught ReferenceError :dbb 未在 file:///android_asset/www/index.html:116 处定义”。 html 文件中的所有代码是:

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=default-width; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html;charset=utf-8">

<title>Embedded Sql Example</title>

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

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

<!-- main scripts used in this example -->
<script type="text/javascript" charset="utf-8">

var db;
var shortName = 'WebSqlDB';
var version = '1.0';
var displayName = 'WebSqlDB';
var maxSize = 65535;

function errorHandler(transaction, error) {
alert('Error: ' + error.message + ' code: ' + error.code);

}

function successCallBack() {
alert("DEBUGGING: success");

}

function nullHandler(){};


function onBodyLoad(){

alert("DEBUGGING: we are in the onBodyLoad() function");

if (!window.openDatabase) {

alert('Databases are not supported in this browser.');
return;
}

db = openDatabase(shortName, version, displayName,maxSize);

db.transaction(function(tx){

// you can uncomment this next line if you want the User table to be empty each time the application runs
// tx.executeSql( 'DROP TABLE User',nullHandler,nullHandler);

tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)', [],nullHandler,errorHandler);
},errorHandler,successCallBack);

}

function ListDBValues() {

if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}

$('#lbUsers').html('');

db.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM User;', [],
function(transaction, result) {
if (result != null && result.rows != null) {
for (var i = 0; i < result.rows.length; i++) {
var row = result.rows.item(i);
$('#lbUsers').append('<br>' + row.UserId + '. ' +
row.FirstName+ ' ' + row.LastName);
}
}
},errorHandler);
},errorHandler,nullHandler);

return;

}

function AddValueToDB() {

if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}

db.transaction(function(transaction) {
transaction.executeSql('INSERT INTO User(FirstName, LastName) VALUES (?,?)',[$('#txFirstName').val(), $('#txLastName').val()], nullHandler,errorHandler);
});

ListDBValues();

return false;

}

</script>
</head>
<body onload="onBodyLoad();">
<h1>WebSQL</h1>
<input id="txFirstName" type="text" placeholder="FirstName">
<input id="txLastName" type="text" placeholder="Last Name">
<input type="button" value="Add record" onClick="AddValueToDB();">
<input type="button" value="Refresh" onClick="ListDBValues();"> <br>
<br>
<span style="font-weight:bold;">Currently stored values:</span>
<span id="lbUsers"></span>
</body>
</html>

如有任何帮助,我们将不胜感激。

最佳答案

看来你调用 openDatabase 没问题。但是,如果您查看 Cordova ( http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#openDatabase ) 的示例,您会注意到该示例正在监听 deviceready 事件,而不是等待正文加载。当 deviceready 事件触发时,意味着 Cordova API 已准备好使用。当正文加载时,仅意味着 WebClient 已完成页面加载,但不能保证其他一切都已准备就绪。

关于cordova - Uncaught ReferenceError : dbb is not defined at file:///android_asset/www/index. html(Phonegap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com