Jquery / Javascript sqlite:获取数据时出错

时间:2015-05-13 14:17:46

标签: javascript jquery sqlite

我通过Google搜索找到了这个tutorial

创建表正在运行,但在获取数据时显示警报;说未定义。警惕之后它也给了我结果。以下是功能,请帮助

var db = openDatabase("mydb", "1.0", "mydb", 200000);
`var dataset;`
var createtablelogin = "CREATE TABLE IF NOT EXISTS login (id INTEGER PRIMARY KEY AUTOINCREMENT,onlineid INTEGER, name TEXT, email TEXT,password TEXT,mobile INTEGER,employeeid INTEGER)";

var statementchecklogin="SELECT * FROM login";

function initDatabase(){
    try {
        if (!window.openDatabase)
        {
            alert('Databases are not supported in this browser.');
        } else {
            createtable(createtablelogin);
        }
    }catch (e){
        if (e == 2) {
            alert("Invalid database version.");
        } else {
            alert("Unknown error " + e + ".");
        }
        return;
    }
}

function itsokay(){
    console.log('DB initiated');
}

function onError(tx, error){
    alert(error.message);
}

function createtable(stmt){
    db.transaction(function (tx) { tx.executeSql(stmt, [],itsokay,onError);});
}

function showRecords(stmt,arrgs){
    db.transaction(function (tx) {
        tx.executeSql(stmt, arrgs, function (tx, result) {
            dataset = result.rows;
        });
    });
}

$(document).ready(function){
  initdatabase();
  showRecords(statementchecklogin,[]);
});

我做错了什么?

SLOVED //var dataset; --> this was the bug 每当调用数据集时,它都在访问此变量。刚删除它。

0 个答案:

没有答案