Web-SQL查询会触发成功和失败回调

时间:2012-12-21 11:39:58

标签: javascript web-sql

我在谷歌浏览器中使用网络数据库,而executeSql函数会触发成功和失败信号!

function succes(){
    alert("succes");
}

function failure(){
    alert("failure");
}

var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS " +
              "goal(ID INTEGER PRIMARY KEY ASC, goals TEXT, added_on DATETIME, appartient INTEGER, ok INTEGER)", []);
 });

 $('#button').click(function(){
    db.transaction(function(tx){
    var goalText = $('#entry').val();
    var addedOn = new Date();
    var appartient = 0;
    var ok = 0;
    alert(goalText);
    tx.executeSql("INSERT INTO goal(goals, added_on, appartient, ok) VALUES (?,?,?,?)",
    [goalText, addedOn, appartient, ok],
    succes(),
    failure());
 });

});

有什么问题?

1 个答案:

答案 0 :(得分:1)

致电 succesfailure并将其(undefined返回值传递给executeSql

取走()并传递函数。