5
我已經創建了使用phonegap模板的HTML5/JQuery項目。我正試圖在本地數據庫上存儲信息。目前,我正在使用模擬器ElectricMobileStudio2012進行測試。 我收到的錯誤:在這行代碼 「SECURITY_ERR DOM異常18」:Security_ERR:DOM異常18 openDatabase()使用Phonegap
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);
}
}
我把這個,但是它從來沒有叫... – ekatz
你在哪裏添加此?你如何測試它? 如果您在普通瀏覽器中測試它,它將永遠不會觸發。 – Fraccus
是的,這固定它。 – shamittomar