Security_ERR:DOM异常18 openDatabase()使用Phonegap [英] Security_ERR: DOM Exception 18 openDatabase() using Phonegap

查看:76
本文介绍了Security_ERR:DOM异常18 openDatabase()使用Phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建和HTML5 / JQuery项目使用phonegap模板。我试图将信息存储在本地数据库。目前,我使用模拟器ElectricMobileStudio2012为了测试。
我在此代码行上收到错误 Security_ERR:DOM异常18

I have created and HTML5/JQuery project using phonegap template. I am trying to store information on local database. Currently, I am using the simulator ElectricMobileStudio2012 in order to test. I am receiving the error "Security_ERR: DOM Exception 18" on this line of code:

var db = window.openDatabase("MobileInspection", "1.0", "Mobile Inspection Database", 200000);

这是我的代码。我已经坚持了几天,我甚至尝试使用这些代码行来解决错误:

Here is my code. I have been stuck on this for days and I even tried using these lines of code to get around the error:

navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;

window.droiddb = new DroidDB();






这是我的代码:


Here is my code:

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);
    }
}


推荐答案

I

确保所有localstorage调用在deviceready块中执行:

Make sure that all localstorage calls executes within the deviceready block:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    //do ALL your localstorage stuff here
}

这篇关于Security_ERR:DOM异常18 openDatabase()使用Phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆