无法使用javascript保存数据

时间:2014-12-26 14:59:13

标签: javascript web-sql tizen-web-app

我正在编写应用程序,我需要存储用户生成的数据。这是代码:

<script type="text/javascript">
            function saveData() {
                var db;
                var version = 1.0;
                var dbName = "periodtwodb";
                var dbDisplayName = "periodtwo_db";
                var dbSize = 2 * 1024 * 1024;
                try {
                    db = openDatabase(dbName, version, dbDisplayName, dbSize,
                            function(dbName) {
                                alert("database creation callback");
                            });
                } catch (err) {
                    console.log(err);
                }
                dbName
                        .transaction(
                                function(sqlTransaction) {
                                    sqlTransaction
                                            .executeSql(
                                                    "CREATE TABLE IF NOT EXISTS notes(Date TEXT PRIMARY KEY bloodFlow INTEGER, p_start BOOLEAN, note TEXT, medicine TEXT, intercourse BOOLEAN, weight INTEGER, temparature INTEGER)",
                                                    [],
                                                    function(sqlTransaction,
                                                            sqlResultSet) {
                                                        sqlTransaction
                                                                .executeSql("INSERT INTO notes (Date, bloodFlow, p_start, note, medicine, intercourse, weight, temparature) VALUES ("+dte+", "+star+", "+checkone+", "+nte+", "+med+", "+checktwo+", "+wgt+", "+wgt1+")");
                                                                alert("table created successfully");
                                                    },
                                                    function(sqlTransaction,
                                                            sqlError) {
                                                        console.log(sqlError);
                                                        alert("Transaction error");
                                                    });
                                },
                                function() {
                                    alert("SQL statements were executed successfully.");
                                });
            }
        </script>

Uncaught TypeError: undefined is not a function的错误为:dbName.transaction(function(sqlTransaction) {。我该如何解决? 数据库已成功创建,但表格未创建。

1 个答案:

答案 0 :(得分:2)

更改

dbName.transaction(

db.transaction

更新:

"CREATE TABLE IF NOT EXISTS notes(Date TEXT PRIMARY KEY, bloodFlow INTEGER, p_start BOOLEAN, note TEXT, medicine TEXT, intercourse BOOLEAN, weight INTEGER, temparature INTEGER)",