我已经使用 phonegap 模板创建了 HTML5/JQuery 项目。我正在尝试将信息存储在本地数据库中。目前,我正在使用模拟器 ElectricMobileStudio2012 进行测试。我在这行代码中收到错误“ Security_ERR: DOM Exception 18 ”:
var db = window.openDatabase("MobileInspection", "1.0", "Mobile Inspection Database", 200000);
这是我的代码。我已经坚持了好几天了,我什至尝试使用这些代码行来解决这个错误:
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
window.droiddb = new DroidDB();
这是我的代码:
function SaveUserInfoLocally(data) {
try {
var rememberMe = $('#chkRememberMe').is(':checked')
if (rememberMe) {
// TODO: Save user details in local db.
//navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
//window.droiddb = new DroidDB();
var db = window.openDatabase("MobileInspection", "1.0", "Mobile Inspection Database", 200000);
db.transaction(populateUsersTable, errorCB, successCB);
db.transaction(queryDB, errorCB);
}
}
catch (error) {
alert(error);
}
}
function populateUsersTable(tx) {
try {
var userName = window.localStorage.getItem("UserName");
var firstName = window.localStorage.getItem("FirstName");
var lastName = window.localStorage.getItem("LastName");
//alert(userName + " " + firstName + " " + lastName);
tx.executeSql("DROP TABLE IF EXISTS UserDetails");
tx.executeSql("CREATE TABLE IF NOT EXISTS UserDetails (UserName, FirstName, LastName)");
tx.executeSql("INSERT INTO UserDetails (UserName, FirstName, LastName) VALUES ('" + userName + "', '" + firstName + "', '" + lastName + "')");
alert("populate");
}
catch (exception) {
alert(exception);
}
}
function errorCB(err) {
alert("Error processing: " + err);
}
function successCB() {
alert("success!");
}
function queryDB(tx) {
try {
tx.executeSql('SELECT * FROM UserDetails', [], querySuccess, errorCB);
}
catch (exception) {
alert(exception);
}
}
// Testing
function querySuccess(tx, results) {
try {
if (results) {
alert("records");
}
else {
alert(results);
}
}
catch (exception) {
alert(exception);
}
}