javascript - Unable to fetch actual value from Web SQL database; it's returning undefined -
check code:
var db = opendatabase("despesas", "1.0", "despesas db", 2000000); db.transaction(createtbl, errorcb, successcb); function errorcb(err){ alert('error : ' + err.code); } function successcb(){ console.log('db created!'); db.transaction(querydb, errorcb); } function createtbl(tx){ tx.executesql('drop table if exists entries'); tx.executesql('create table if not exists entries (id integer primary key autoincrement, entry text not null)'); } function callpopulate(){ db.transaction( function populatedb(tx){ var userinput = document.getelementbyid('user').value; tx.executesql('insert entries (entry) values (?)', [userinput]); //tx.executesql('insert entries (entry) values ("'+ userinput + '")'); //alert('input ok'); }, errorcb, successcb); } function querydb(tx){ tx.executesql('select * entries',[], querysuccess, errorcb); } function querysuccess(tx, results) { document.getelementbyid('list').innerhtml = ''; var len = results.rows.length; console.log("entries table: " + len + " rows found."); (var i=0; i<len; i++){ item = results.rows.item(i); console.log("row = " + + " id = " + results.rows.item(i).id + " data = " + results.rows.item(i).data); document.getelementbyid('list').innerhtml += '<li>' + item.data + '</li>'; console.log(item); } }
i log item
console, prints object stored. tried console.log(item.data)
, doesn't seem give me result expect. how supposed fix , return real value? using chrome.
it looks don't have column called "data" in table, or not selecting it.
Comments
Post a Comment