Phonegap:INVALID_STATE_ERR:DOM异常11 [英] Phonegap : INVALID_STATE_ERR: DOM Exception 11

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

问题描述


未捕获的错误:INVALID_STATE_ERR:DOM异常11在file:/// android_asset / www / library / custom.js:39


但是当我尝试过程2时,
$ b

  var db = window.openDatabase(Pemberton,1.0,Pemberton Stay App,200000); 
document.addEventListener(deviceready,onDeviceReady,false);
function onDeviceReady(){
db.transaction(populateDB,errorCB,successCB);
}

过程1:

  function populateDB(tx){
tx.executeSql('DROP TABLE IF EXISTS eat');
tx.executeSql('CREATE TABLE IF NOT EXISTS eat(id,image,title)');
var queries = new Array();
$ .getJSON(serviceURL +'category-list.php?cid = 1& p =?',function(data){
var results = data.items;
$ .each结果,函数(索引,记录){
if(record.id!= undefined)
tx.executeSql('INSERT INTO eat(id,image,title)VALUES('+ record.id + ,'+ record.image +','+ record.title +')');
});

}
}

过程2:

  function populateDB(tx)
{
tx.executeSql('INSERT INTO eat(id,image,title)VALUES(2,one.jkd OneFirst)');
tx.executeSql('INSERT INTO eat(id,image,title)VALUES(2,two.png,Second)');
tx.executeSql('INSERT INTO eat(id,image,title)VALUES(3,thr.png,Third)');
tx.executeSql('INSERT INTO eat(id,image,title)VALUES(4,fou.png,Fourth)');
tx.executeSql('INSERT INTO eat(id,image,title)VALUES(5,fiv.png,Fifth)');
}


解决方案

deviceready event see full example http://docs.phonegap.com/ en / 1.2.0 / phonegap_storage_storage.md.html#SQLTransaction

  .... 
/ /等待PhoneGap加载
//
document.addEventListener(deviceready,onDeviceReady,false);

// PhoneGap就绪
//
function onDeviceReady(){
var db = window.openDatabase(Database,1.0,PhoneGap Demo ,200000);
db.transaction(populateDB,errorCB,successCB);
}
....


While I am trying process one it's failing:

Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 at file:///android_asset/www/library/custom.js:39

But when I am trying process two, its just fine.

var db = window.openDatabase("Pemberton", "1.0", "Pemberton Stay App", 200000);
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    db.transaction(populateDB, errorCB, successCB);
}

Process 1:

function populateDB(tx) {
    tx.executeSql('DROP TABLE IF EXISTS eat');
    tx.executeSql('CREATE TABLE IF NOT EXISTS eat (id, image, title)');
    var queries = new Array();
    $.getJSON( serviceURL + 'category-list.php?cid=1&p=?', function(data) {
        var results = data.items;
        $.each(results,function(index,record){
            if( record.id != undefined )
                tx.executeSql('INSERT INTO eat (id, image, title) VALUES ("'+record.id+'","'+record.image+'","'+record.title+'")');
        });

    });    
}

Process 2:

function populateDB(tx) 
{
    tx.executeSql('INSERT INTO eat (id, image, title) VALUES (2,"one.jkd","OneFirst")');
    tx.executeSql('INSERT INTO eat (id, image, title) VALUES (2, "two.png","Second")');
    tx.executeSql('INSERT INTO eat (id, image, title) VALUES (3, "thr.png","Third")');
    tx.executeSql('INSERT INTO eat (id, image, title) VALUES (4, "fou.png","Fourth")');
    tx.executeSql('INSERT INTO eat (id, image, title) VALUES (5, "fiv.png","Fifth")');
}

解决方案

db manipulation must be done after deviceready event see full example http://docs.phonegap.com/en/1.2.0/phonegap_storage_storage.md.html#SQLTransaction

....
// Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is ready
    //
    function onDeviceReady() {
        var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
        db.transaction(populateDB, errorCB, successCB);
    }
....

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

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