0

私はphonegap+sqliteを使用しています。

何かを挿入しようとしています。

これがコードです-

function insertDB() {
        var sqlI = "INSERT INTO post_data(post_text,pdate) VALUES("Hello, world","23-05-2012");
        mydb.transaction(
                             function(transaction) {
                             transaction.executeSql(sqlI, [], nullDataHandler, errorHandler); 
                             });
        console.log("inserted");
        window.location="dashboard.html";
}

window.location="dashboard.html"回線を削除したり、1000msの遅延を設定して実行したりすると、データを挿入できwindow.location="dashboard.html"ます。ただし、上記のコードは機能しません。なんで?

4

1 に答える 1

1

transaction機能は非同期だと思います。リダイレクトをすぐ上に配置してみてください:

mydb.transaction(
    function(transaction) {
        transaction.executeSql(
            sqlI, 
            [],  
            function(transaction, results){
                // passing transaction and results in case you have to display some returned statements
                window.location="dashboard.html";
            },
            nullDataHandler
        ); 
});

ご覧のとおり、リダイレクトはresultHandlerで処理されます。

于 2012-06-23T00:57:12.087 に答える