0

phonegap アプリの back getJSON 応答関数内で sqlite クエリを使用すると問題が発生します。

このコードを適用しようとしましたが、エラーしかありません

INVALID_STATE_ERR: DOM 例外 11: 使用できない、または使用できなくなったオブジェクトを使用しようとしました。

私のコードは

<script>
     document.addEventListener("deviceready", onDeviceReady, false);
     function onDeviceReady() {
        // open DB connection
         var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
         db.transaction(populateDB, errorCB, successCB);
    }

    function populateDB(tx) {

         tx.executeSql('DROP TABLE IF EXISTS buses');
         tx.executeSql('CREATE TABLE IF NOT EXISTS buses (bus_id INTEGER PRIMARY KEY,bus_no TEXT, bus_time TEXT,from_loc TEXT,to_loc TEXT,route TEXT)');
         $.getJSON('http://myegy.me/maryam/asem/api.php?table=trip', function(data) {
              $.each(data, function(key, val) {

                    tx.executeSql('INSERT INTO buses (bus_no,from_loc,to_loc,route) VALUES ("'+val['trip_number']+'","'+val['from_id']+'","'+val['to_id']+'","'+val['stop_station']+'")');
              });
            });

         tx.executeSql('DROP TABLE IF EXISTS bus_stations');
         tx.executeSql('CREATE TABLE IF NOT EXISTS bus_stations (id INTEGER PRIMARY KEY,station_name TEXT, station_description TEXT,station_lat TEXT,station_long TEXT)');
         $.getJSON('http://myegy.me/maryam/asem/api.php?table=station', function(data) {
              $.each(data, function(key, val) {

                    tx.executeSql('INSERT INTO bus_stations (station_name,station_lat,station_long) VALUES ("'+val['station_name']+'","'+val['latitude']+'","'+val['longitude']+'")');
              });
            });

    }

    </script>

この2行の問題

 tx.executeSql('INSERT INTO buses (bus_no,from_loc,to_loc,route) VALUES ("'+val['trip_number']+'","'+val['from_id']+'","'+val['to_id']+'","'+val['stop_station']+'")');

tx.executeSql('INSERT INTO bus_stations (station_name,station_lat,station_long) VALUES ("'+val['station_name']+'","'+val['latitude']+'","'+val['longitude']+'")');
4

1 に答える 1