Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在angular factory中调用opendatabase时,它认为dom异常18错误是安全的_Javascript_Angularjs_Cordova_Web Sql - Fatal编程技术网

Javascript 在angular factory中调用opendatabase时,它认为dom异常18错误是安全的

Javascript 在angular factory中调用opendatabase时,它认为dom异常18错误是安全的,javascript,angularjs,cordova,web-sql,Javascript,Angularjs,Cordova,Web Sql,我正在vs2015中开发Angularjs应用程序。 我想通过工厂函数在websql中打开数据库。在ripple emulator中测试应用程序时,它运行良好(在android操作系统4.4版及更高版本中也运行良好),但在android操作系统4.2版及更低版本中测试应用程序时,它会抛出安全性\u err dom异常18。 更奇怪的是,当我在简单的java脚本文件中打开同一个数据库时,它在ripple和所有设备中都能完美地工作 这是我的工厂代码: angular.module('InnkeyAl

我正在vs2015中开发Angularjs应用程序。 我想通过工厂函数在websql中打开数据库。在ripple emulator中测试应用程序时,它运行良好(在android操作系统4.4版及更高版本中也运行良好),但在android操作系统4.2版及更低版本中测试应用程序时,它会抛出
安全性\u err dom异常18
。 更奇怪的是,当我在简单的java脚本文件中打开同一个数据库时,它在ripple和所有设备中都能完美地工作

这是我的工厂代码:

angular.module('InnkeyAlert.services', ['InnkeyAlert.config'])

// DB wrapper

.factory('DB', function ($q, DB_CONFIG) {

try {
    var self = this;
    self.db = null;

    self.init = function () {
        alert("DB init start!");
        // Use self.db = window.sqlitePlugin.openDatabase({name: DB_CONFIG.name}); in production
        self.db = window.openDatabase(DB_CONFIG.name, '1.0', 'database', -1);
        alert("DB open!");
        angular.forEach(DB_CONFIG.tables, function (table) {
            var columns = [];

            angular.forEach(table.columns, function (column) {
                columns.push(column.name + ' ' + column.type);
            });

            var query = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + columns.join(',') + ')';
            self.query(query);
            //console.log('Table ' + table.name + ' initialized');
        });
        alert("table created !");
    };

    return self;

} catch (e) {
    //alert("Db factory: "+e.message);
}

})
以下是我的index.js文件代码:

    var app = {

        // Application Constructor
        initialize: function () {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function () {
            alert("hi");
            document.addEventListener('deviceready', this.onDeviceReady, false);        
        },

        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicitly call 'app.receivedEvent(...);'
        onDeviceReady: function () {
            app.receivedEvent('deviceready');
            alert("Device ready end...");
            try {
                angular.injector(['InnkeyAlert']).get('DB').init();
                alert("inti db called...");
            } catch (e) {
                alert("index 101: " + e.message);
            }
        },
        // Update DOM on a Received Event
        receivedEvent: function (id) {

        }
    };

这在低于4.4的Android版本中是个问题。答复如下:

您可以从WebView中的文件://URL使用Web SQL。科尔多瓦人设法做到了。你必须做三件事:

1) 调用setDatabaseEnabled()(duh):

2) 设置数据库文件路径。是的,这在Android 4.4中已被弃用,但如果您想避免pre-Kitkat中的DOM异常18,则必须使用它:


3) 设置OneExceededDatabaseQuota处理程序。是的,它在Android 4.4中被弃用了,诸如此类。

在哪一行抛出了
security\u err dom exception 18
?请添加stacktrace或logcat输出。@JohannesJander-in my factory init()->self.db=window.openDatabase(db_CONFIG.name,'1.0','database',-1);把这个放在哪里?我的代码是基于javascript的。上面的代码看起来像c#或vb.net代码,这是Java。在javascript中不能这样做。如果您确实需要支持Android 4.2,那么您需要使用Java来准备webview。但是如何将该代码与我的Java脚本代码集成呢。?有什么解决方案吗?像Cordova这样的技术。在普通的web应用程序中无法做到这一点。