2014-12-26 52 views
0

我在寫應用程序,我需要存儲用戶生成的數據。下面是代碼:無法使用javascript保存數據

<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) {。我該如何解決它? 數據庫正在成功創建,但表未創建。

回答

2

變化

dbName.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)",