我使用phonegap模板创建了
HTML5 /
JQuery项目.我试图在本地数据库上存储信息.目前,我正在使用模拟器ElectricMobileStudio2012进行测试.
我在这行代码中收到错误“Security_ERR:DOM Exception 18”:
我在这行代码中收到错误“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",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,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); } }
解决方法
我有一个类似的问题 – 因此我在这个问题上遇到了麻烦.
确保在deviceready块中执行所有localstorage调用:
document.addEventListener("deviceready",onDeviceReady,false); function onDeviceReady() { //do ALL your localstorage stuff here }