JS没有进入交易功能

时间:2015-04-22 08:54:44

标签: javascript html5 web-sql

我有以下代码:

var db = openDatabase('CBDB', '1.0', 'mySpecialDatabaseThatWontWork',10*1024*1024);
    db.transaction(function (nw){
        nw.executeSql('Drop TABLE user');           
    });

    function db1(){
        var db = openDatabase('CBDB', '1.0', 'mySpecialDatabaseThatWontWork',10*1024*1024);
        db.transaction(function (tx){
            createDB();
            queryDB();
        });
        function createDB(){
            db.transaction(function (tx){
            tx.executeSql('CREATE TABLE IF NOT EXISTS login(empid unique, name varchar(20), pass varchar(20), manager varchar(20))');
            tx.executeSql('INSERT INTO login (empid,name,pass,manager) VALUES ("1234567","Krishnaji","12345","9999999")');
            tx.executeSql('INSERT INTO login (empid,name,pass,manager) VALUES ("1000001","Gourav","12345","1234567")');
            tx.executeSql('INSERT INTO login (empid,name,pass,manager) VALUES ("1000002","Manju","12345","1234567")');
            tx.executeSql('CREATE TABLE IF NOT EXISTS user(empid varchar(10))');
            });
        }
        function queryDB(){
            db.transaction(function (tx){
            var x = $('#nameT').val();
            tx.executeSql('INSERT INTO user (empid) VALUES (?)', [x]);
            var u = $("#nameT").val();
            var p = $("#nameP").val();
            tx.executeSql('SELECT * FROM login WHERE empid="?" and pass="?"',[u,p], function valid(tx,results){
                var len = results.rows.length;
                console.log(len);
                if (len == 1) {
                    window.location.assign("www/landing.html");
                } else{
                    //alert("Invalid Employee ID or Password");
                };
            });
        });
        }
        }

现在的问题是javascript没有进入交易功能。

我已经尝试过关于删除警报的类似问题的解决方案,但它对我没有用。

1 个答案:

答案 0 :(得分:0)

问题是transaction()只执行一个executeql语句。